Collectives on Stack Overflow. Learn more. Asked 5 years, 10 months ago. Active 5 years, 10 months ago. Viewed 8k times. I am using Cordova FileTransfer object to download a file from a url to device. Improve this question. Shoreki Shoreki 4 4 gold badges 11 11 silver badges 32 32 bronze badges.
Add a comment. Active Oldest Votes. Improve this answer. Let'sRefactor Let'sRefactor 3, 4 4 gold badges 26 26 silver badges 41 41 bronze badges. It works best on Android, iOS is a bit different due to the app sandboxing so you need to handle retrieving files yourself. I also use the Cordova device plugin to determine what device the app is running on, I can then change storage paths to suit:.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Cordova - Download a file in download folder Ask Question. Asked 4 years, 7 months ago. Active 4 years, 7 months ago. Viewed 30k times. Improve this question. Zappescu Zappescu 1, 2 2 gold badges 10 10 silver badges 24 24 bronze badges.
Add a comment. Active Oldest Votes. When you have the FileEntry object, download the file using the download method of the FileTransfer object. The 3rd argument to the download function of FileTransfer is the success callback, which you can use to call the app's readBinaryFile function. In this code example, the entry variable is a new FileEntry object that receives the result of the download operation. Depending on your app requirements, you may want to read the file. Once you read the file successfully, construct a Blob object using the result of the read.
As you saw previously, you can call FileEntry. When you upload a File using the File-Transfer plugin, use the File plugin to provide files for upload again, they must be FileEntry objects. Before you can upload anything, create a file for upload using the getFile method of DirectoryEntry. In this example, create the file in the application's cache fs.
Then call the app's writeFile function so you have some content to upload. Forward the FileEntry object to the upload function. To perform the actual upload, use the upload function of the FileTransfer object. Again, the success handler for the FileTransfer.
0コメント