I face a problem with IOS file download.
I'm trying to make the user download a file when he click on a link. I create a blob and make a click on the link.
It's working fine on desktop but not on mobile...
let blob = new Blob([success], { type: success.type });
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, dd.filename);
} else {
let a = document.createElement('a');
let url = URL.createObjectURL(blob);
a.href = url;
a.download = dd.filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
this.flashService.success('Dernières consultations', 'Ce document a été téléchargé');
this.downloaded.emit(this.document);
}
Thanks,
I finally found the answer.
{ type: success.type }
I had the wrong type in this variable that was the reason. Mobile navigator failed to recognize the file type
Related
I am using nativescript-mediafilepicker as means of choosing a file, and this can read external storage successfully (I have downloaded a PDF to the 'downloads' folder on iOS and I am able to pick it.) I then try to load the file using the file system module from nativescript library, and this fails because it is listed as NativeScript encountered a fatal error: Uncaught Error: You can’t save the file “com.xxxxxx” because the volume is read only. This doesn't make sense as I am trying to read anyway - I don't understand where the saving part is from. The error comes from fileSystemModule.File.fromPath() line.
Something to note that file['file'] is file:///Users/adair/Library/Developer/CoreSimulator/Devices/82F397CE-B0B3-4ADD-AD52-805265C7AC49/data/Containers/Data/Application/7B47A8BD-6DBA-42CF-8792-38A8C5E61174/tmp/com.xxxxxx/test.pdf
Is the file automatically being pulled to an application specific directory after this media picker?
getFiles() {
let extensions = [];
if (app.ios) {
extensions = [kUTTypePDF]; // you can get more types from here: https://developer.apple.com/documentation/mobilecoreservices/uttype
} else {
extensions = ["pdf"];
}
const mediaFilePicker = new Mediafilepicker();
const filePickerOptions = {
android: {
extensions,
maxNumberFiles: 1,
},
ios: {
extensions,
maxNumberFiles: 1,
},
};
masterPermissions
.requestPermissions([masterPermissions.PERMISSIONS.READ_EXTERNAL_STORAGE,masterPermissions.PERMISSIONS.WRITE_EXTERNAL_STORAGE])
.then((fulfilled) => {
console.log(fulfilled);
mediaFilePicker.openFilePicker(filePickerOptions);
mediaFilePicker.on("getFiles", function (res) {
let results = res.object.get("results");
let file = results[0];
console.dir(file);
let fileObject = fileSystemModule.File.fromPath(file["file"]);
console.log(fileObject);
});
mediaFilePicker.on("error", function (res) {
let msg = res.object.get("msg");
console.log(msg);
});
mediaFilePicker.on("cancel", function (res) {
let msg = res.object.get("msg");
console.log(msg);
});
})
.catch((e) => {
console.log(e);
});
},
The issue I have experienced is resultant of the expectation of File.fromPath and what is returned by the file picker. File picker is returning a "file://path" URI, and File.fromPath is expecting a string of just "path".
Simply using the following instead is enough.
let fileObject = fileSystemModule.File.fromPath(file["file"].replace("file://","");
I implemented a Jersey REST service to download the zip file.
Now, I would like to use axios in front end to download the zip file.
Everything is fine in PC Chrome but when tried with Safari on iPad it opens a tab with name "unknown".
I have searched some articles and mentioned that this may related to IOS safari compatibility.
e.g. https://caniuse.com/#feat=download
However, I also want know if there is any method to show the downloaded file as "file.zip" for safari.
Below is my code
Backend:
#GET
#Path("/getTestingReport")
#Produces("application/zip")
public Response getTestingReport() throws Exception {
// set file (and path) to be download
File file = new File("C:/Users/abc/Desktop/test.zip");
ResponseBuilder responseBuilder = Response.ok((Object) file);
responseBuilder.header("Content-Disposition", "attachment; filename=\"MyJerseyZipFile.zip\"");
return responseBuilder.build();
}
Frontend:
axios.get("report/getTestingReport").then((response) => {
console.log("response", response)
var blob = new Blob([response.data], { type: "application/zip" });
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.zip');
document.body.appendChild(link);
link.click();
}).catch((error) => {
console.error("error response", error.response)
});
May I have any suggestion?
I'm trying to make a mp3 player with ionic media plugin.
First I download song on local storage via path
let filePath;
if(this.platform.is('android'))
{
filePath = this.file.externalDataDirectory;
}
else
{
filePath = this.file.documentsDirectory;
}
filePath = filePath +'810.mp3';
after that we get such path
file:///var/mobile/Containers/Data/Application/5DC6D2D0-6336-4C6E-A39E-5D5FD7D8AF7B/Library/Cloud/810.mp3
So for example we have such an object
track = {
'name':'Name of Song',
'filePath': filePath
}
I create
const file:MediaObject = this.media.create(track.filePath);
and when time comes to play
file.play();
Whole app crashes without giving me a hint of error.
This plugin normally plays files on Android from both localPath and internetPath.
On iOS it plays only from internet but crashes when plays local files. Please help.
So I found the solution. It was here.
https://forum.ionicframework.com/t/ios-9-cant-play-audio-video-files-that-are-downloaded-to-device/37580
For example.
track = {
'name':'Name of Song',
'filePath': '';
}
if(this.platform.is('android'))
{
track.filePath = this.file.externalDataDirectory;
}
else
{
track.filePath = this.file.documentsDirectory;
}
track.filePath = track.filePath +'810.mp3';
const transfer = this.transfer.create();
let url = "http://someLink.com/someFileName.mp3";
transfer.download(url, track.filePath).then((entry)=>{
// **code here will be executed when track is downloaded**
// and only for ios local file system we need to create a special link to this file
// so that cordova media plugin could read this file and if necessary to delete it
// with cordova file plugin by this link also.
if(this.platform.is('ios'))
this.file.resolveLocalFilesystemUrl(track.filePath).then((entry)=>{
track.filePath = entry.toInternalURL;
});
Actually there was another way to make iOS play file by removinh file:// from beging of track.filePath but then you will face with another issue. You won't be able do delete it by this path later.
Using the Node integration provided by cloudinary_npm, I'm getting the following message back when I try to upload:
{ error: { message: 'Invalid Signature t7233823748278473838erfndsjy8234. String to sign - \'timestamp=1439054775\'.', http_code: 401 } }
I retrieve then pass my image to the backend like this:
$scope.previewFile = function() {
var file = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
if (file) {
reader.readAsDataURL(file);
} else {
preview.src = "";
}
reader.onloadend = function () {
base64img = reader.result;
preview.src = base64img;
console.log(base64img);
};
};
$scope.submitPic = function() {
$http.post('http://localhost:3000/story/pic', {img: base64img})
.success(function(data){
preview.src = "";
})
.error(function(err){
console.log(err);
});
};
Then in the back, I have the following configuration and routes, both straight from the docs:
var cloudinary = require("cloudinary");
var CLOUD_API_SECRET = require("../constants.js");
cloudinary.config({
cloud_name: 'some_cloud',
api_key: '63789865675995',
api_secret: CLOUD_API_SECRET
});
router.post('/pic', function(req, res, next) {
var img = req.body.img;
cloudinary.uploader.upload(img, function(result) {
});
res.status(200).send('ok');
});
Does anyone recognize what I might be doing wrong? I've been troubleshooting this for hours. I'm at a dead end.
make sure you have placed your cloudinary secret inside a ''(quote/inverted comma).make sure the resulting statement should mean :
var CLOUD_API_SECRET ='some_cloudinary_secret_xxx';
check this value in the js file from where you are fetching this value.
From Java level I fixed this issue by changing the time zone to America/New_York time:
Long time = new Long(System.currentTimeMillis() );
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.setTimeZone(TimeZone.getTimeZone("America/New_York"));
Date date = new Date(sdf.format(new Date(time)));
long utcDateInMilliSeconds = date.getTime();
params.put("timestamp", new Long(utcDateInMilliSeconds/1000));
I had this very same error running similar code route on nodejs using cloudinary's sdk.
The issue turned out to be a typo within my API_SECRET.
Like Jeremy said, It's mostly typo or white space in your API secret.
Try to use your API secret directly in the configuration (not via variable)
am facing an problem using getUrl in as2 , when i run the swf using test movie the link work probably , but if i run the published file am getting a wrong url , example
-run via test movie : getting -> www.google.com
-run the published swf file : getting ->file:///C:/Users/moata/Desktop/actionScript/www.google.com
dots.ignoreWhite = true;
dots.load('links.xml');
dots.onLoad = function(success:Boolean){
if(success){
xmlNode = this.firstChild;
var all:MovieClip = attachMovie("test","all",depth);
setTimeout(startMe,6000);
}else{
trace("Could not load XML");
}
function startMe (){
for(i=1;i<=6;i++){
all['btn'+i].onRelease = function() {
for(i=0;i<6;i++){
var name = this;
if(String(xmlNode.childNodes[i].attributes.TITLE) == String(name)){
getURL(xmlNode.childNodes[i].childNodes[0].nodeValue, "_blank");
}
}
}
}
}
};
i just need add http:// in getRUL as follow
getURL("http://www.google.com"); , instead of getURL("www.google.com");