Save file to public directory using Cordova FileTransfer

kolli

I need to download files on my mobile device and make them accessible for other apps (using Android and iOS).

I managed to download a file to the SD card (cordova.file.externalDataDirectory), but this only exists on Android and even then I cannot rely on every device having an SD card.

When I download to the device storage (cordova.file.dataDirectory), the file is private to my app and therefore not accessible for other apps. The file can be opened in the InAppBrowser, but I would prefer to use the respective default app.

Is there a way to get a path to a directory publicly available on all devices?

The paths returned by the solution suggested in https://stackoverflow.com/a/21375812/3432305 are both private on Android...

EDIT:

I think I should describe my use case so it's clearer what I'm trying to achieve: I want to open files from my in app chat using the respective default app (pdf viewer, image viewer etc.). Because the Cordova File Opener plugin only accepts files from the local file system, I need to save them first. But they don't necessarily need to be accessible from outside my app afterwards...

DaveAlden

On Android, external storage directories always exist; if the device doesn't have a physical SD card, Android will emulate it. see getExternalStorageDirectory :

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

Therefore cordova.file.externalDataDirectory will always resolve. However, for sharing data between apps, you probably want to use cordova.file.externalRootDirectory - External storage (SD card) root. See cordova-plugin-file.

This way you can store files in a place that's easier to access from another app e.g. /sdcard/my_shared_data/

On iOS, it's more difficult to share files because apps are intentionally isolated from each other due to security policy, as Apple's Inter-App Communication Guide says:

Apps communicate only indirectly with other apps on a device

You best bet on iOS is to share the data by synching it via iCloud. See the section Configuring a Common Ubiquity Container for Multiple Apps in iCloud Design Guide, which says:

... perhaps you provide two apps that interoperate and need access to each other’s files. In both of these examples, you obtain the needed access by specifying a common ubiquity container and then requesting access to it from each app.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error uploading file using Cordova filetransfer in SSL environment

From Dev

File-upload error using Cordova FileTransfer to NodeJS

From Dev

Download file via FileTransfer in Cordova

From Dev

Download file via FileTransfer in Cordova

From Dev

Unable to upload file with Cordova FileTransfer

From Dev

Unable to download file in Cordova and Ionic with FileTransfer

From Dev

File upload error code 1 in ng-cordova filetransfer plugin

From Dev

How to upload cordova filetransfer using server asp.net

From Dev

Cordova FileTransfer Download error

From Dev

FileTransfer Cordova download path

From Dev

FileTransfer Cordova download path

From Dev

How to download and save a file using phonegap/cordova on Android

From Dev

Could not access directory and subdirectory using cordova File API

From Dev

Cordova Android Filetransfer returning null

From Dev

Cordova FileTransfer show downloaded image

From Dev

Cordova/Phonegap does not recognise FileTransfer

From Dev

Cordova FileTransfer not sending custom headers

From Dev

Cordova: Uncaught ReferenceError: FileTransfer is not defined

From Dev

Not able to save the file in custom path directory using Python Telegram bot

From Dev

Save an Excel file into Local Directory using c#

From Dev

How to browse directory and save path as a variable in a file using tcl/tk

From Dev

Cordova/Phonegap FileTransfer.upload() error code = 1 (FILE_NOT_FOUND_ERR)

From Dev

How can I upload files to Amazon S3 using Cordova FileTransfer?

From Dev

Ionic: Getting Error Code 3 when uploading image using ng-cordova fileTransfer and Camera plugin

From Dev

Cordova file plugin - save file in device

From Dev

Can't read a file from android directory using cordova-plugin-file plugin

From Dev

phpqrcode - save file to temporary directory

From Dev

Save image file to temp directory

From Dev

Save CSV file into specific directory

Related Related

  1. 1

    Error uploading file using Cordova filetransfer in SSL environment

  2. 2

    File-upload error using Cordova FileTransfer to NodeJS

  3. 3

    Download file via FileTransfer in Cordova

  4. 4

    Download file via FileTransfer in Cordova

  5. 5

    Unable to upload file with Cordova FileTransfer

  6. 6

    Unable to download file in Cordova and Ionic with FileTransfer

  7. 7

    File upload error code 1 in ng-cordova filetransfer plugin

  8. 8

    How to upload cordova filetransfer using server asp.net

  9. 9

    Cordova FileTransfer Download error

  10. 10

    FileTransfer Cordova download path

  11. 11

    FileTransfer Cordova download path

  12. 12

    How to download and save a file using phonegap/cordova on Android

  13. 13

    Could not access directory and subdirectory using cordova File API

  14. 14

    Cordova Android Filetransfer returning null

  15. 15

    Cordova FileTransfer show downloaded image

  16. 16

    Cordova/Phonegap does not recognise FileTransfer

  17. 17

    Cordova FileTransfer not sending custom headers

  18. 18

    Cordova: Uncaught ReferenceError: FileTransfer is not defined

  19. 19

    Not able to save the file in custom path directory using Python Telegram bot

  20. 20

    Save an Excel file into Local Directory using c#

  21. 21

    How to browse directory and save path as a variable in a file using tcl/tk

  22. 22

    Cordova/Phonegap FileTransfer.upload() error code = 1 (FILE_NOT_FOUND_ERR)

  23. 23

    How can I upload files to Amazon S3 using Cordova FileTransfer?

  24. 24

    Ionic: Getting Error Code 3 when uploading image using ng-cordova fileTransfer and Camera plugin

  25. 25

    Cordova file plugin - save file in device

  26. 26

    Can't read a file from android directory using cordova-plugin-file plugin

  27. 27

    phpqrcode - save file to temporary directory

  28. 28

    Save image file to temp directory

  29. 29

    Save CSV file into specific directory

HotTag

Archive