Coder Social home page Coder Social logo

dsgriffin / ionic-3-file-transfer-example Goto Github PK

View Code? Open in Web Editor NEW
112.0 14.0 60.0 1.65 MB

:file_folder: File Transfer in Ionic 3 using Ionic Native's File and Transfer modules

TypeScript 43.51% HTML 19.31% CSS 29.89% JavaScript 7.29%
js typescript file-transfer ionic javascript ionic3

ionic-3-file-transfer-example's People

Contributors

dsgriffin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ionic-3-file-transfer-example's Issues

Pdf Download

Can I do trick to open pdf and save file in downloads folder? (Other page in your example)

Cannot get Internal Storage permission at Run Time

The code works fine but the only issue is that i am saving those files on the device internal storage but i have to manually give the permission of accessing the Storage.
Is there any way to give permissions at run time?

P.S - I have tried cordova.Diagnostic plugin but there is no option to ask permission for internal storage.It does have one for external Storage but that piece of code doesn't seems to work

when download for the 2nd time, it won't replace old file

I have a list of coffees and each coffee contain a url that I can download its image from firebase storage.

when I'm looping through each coffee from coffees, fileTransfer.download method downloads images fine (example of the location where the image is stored (file:///var/mobile/Containers/Data/Application/C406AEAB-1538-47FD-9FB7-79ED5D208795/Library/NoCloud/-KmAFkXiDElkR3tysdK5), but when:

  1. I change the coffee images (coffee.url changes)
  2. when I try to run the loop to download each coffee from coffees for the 2nd time, it downloads the new images and store them in the same location (for ex, file:///var/mobile/Containers/Data/Application/C406AEAB-1538-47FD-9FB7-79ED5D208795/Library/NoCloud/-KmAFkXiDElkR3tysdK52), but it won't display new images (instead the old images are still there).

Please see my code here:
// Loop through all coffees to store images locally
this.coffees.forEach((coffee: Coffee) => {

const url = coffee.url;
const fileTransfer = this.transfer.create();
// Start downloading image to store it locally
fileTransfer.download(url, this.file.dataDirectory + coffee.$key)
.then((entry) => {
  count++;
  coffee.url = entry.toURL();
  // console.log(`entry url ${entry.toURL()}`);
  // If last coffee, then save coffees in storage
  if (count == coffeesLength) {
    this.storage.set('coffees', this.coffees)
    .then(
      // Set this coffees to be the stored coffees
      storedCoffees => {
        this.coffees = storedCoffees;
      }
    )
    .catch(err => console.log(err));
  }
})
.catch((err => console.log(err));

});

To fix around I added keepTrack variable (please see the code below), so for the first time download, it stored in a file name file:///var/mobile/Containers/Data/Application/C406AEAB-1538-47FD-9FB7-79ED5D208795/Library/NoCloud/-KmAFkXiDElkR3tysdK51 and the second time it will be -KmAFkXiDElkR3tysdK52 and so on... after that new images display fine on my mobile. Is there anyway to write a method that will automatically replace old files when re-download again?

let keepTrack = 1;

// Loop through all coffees to store images locally
this.coffees.forEach((coffee: Coffee) => {

const url = coffee.url;
const fileTransfer = this.transfer.create();
// Start downloading image to store it locally
fileTransfer.download(url, this.file.dataDirectory + coffee.$key + keepTrack)
.then((entry) => {
  count++;
  coffee.url = entry.toURL();
  // console.log(`entry url ${entry.toURL()}`);
  // If last coffee, then save coffees in storage
  if (count == coffeesLength) {
    this.storage.set('coffees', this.coffees)
    .then(
      // Set this coffees to be the stored coffees
      storedCoffees => {
        this.coffees = storedCoffees;
        keepTrack++;
      }
    )
    .catch(err => console.log(err));
  }
})
.catch((err => console.log(err));

});

Not able to save image in externalRootDirectory path

I saved image in all directory path like cordova.file.externalApplicationStorageDirectory,cordova.file.externalDataDirectory,cordova.file.applicationStorageDirectory,cordova.file.applicationStorageDirectoryetc but whenever i try to save in externalRootDirectory path it is showing error "download failed pug.jpg was not successfully download/ error code 1. I am using real device .

ERROR Error: Uncaught (in promise): ReferenceError: cordova is not defined

I have downloaded the files setup the code in my local machine. I am using ionic cli 3.8. When I ran the command ionic serve, it gave me the below warnings.

[WARN] Detected @ionic/cli-plugin-cordova in your package.json. As of CLI 3.8, it is no longer needed. You can uninstall it: npm uninstall --save-dev --save-exact @ionic/cli-plugin-cordova [WARN] Detected @ionic/cli-plugin-ionic-angular in your package.json. As of CLI 3.8, it is no longer needed. You can uninstall it: npm uninstall --save-dev --save-exact @ionic/cli-plugin-ionic-angular

When the app was displayed in the browser, clicking on the download button was throwing the below error message
ERROR Error: Uncaught (in promise): ReferenceError: cordova is not defined
And clicking on the retrieve download image was throwing the File retrieval Failed! alert message.

Error : Cannot find name 'cordova'.

i applied the same code to my project but is shows this error :

L25:    this.storageDirectory = cordova.file.documentsDirectory;

        Cannot find name 'cordova'.

  L27:  else if(this.platform.is('android')) {
  L28:    this.storageDirectory = cordova.file.dataDirectory;

        Cannot find name 'cordova'.

  L43:        const imageLocation = `${cordova.file.applicationDirectory}www/assets/img/${image}`;

Error code 3

I have all dependencies installed, when running on both iOS and Android device I get an Error code: 3. It doesn't explain what the error is so I'm finding hard to solve. I've also looked through any relevant documentation but couldn't seem to find anything. Any help? Thanks.

Read back file

How would you read back in the file? I've tried using the url from target path, but on iOS it gives me an error.

Failed to load resource: The operation couldn’t be completed. Operation not permitted

Unable to find downloaded image

I am unable to find downloaded image either in mac or iPhone.
The path is being display there, does not available over there in device.
Here is my mac local setup-

******************************************************
Your system information:

Cordova CLI: 6.4.0 
Ionic Framework Version: 2.0.0
Ionic CLI Version: 2.1.8
Ionic App Lib Version: 2.1.4
Ionic App Scripts Version: 1.0.0
ios-deploy version: Not installed
ios-sim version: 5.0.8 
OS: OS X Yosemite
Node Version: v6.2.2
Xcode version: Xcode 7.2 Build version 7C68
******************************************************

How to find that image!!!

Android Download file not working

Hi,
I have configured your project and installed the apk on my device and on pressing download image button I received message box that file is downloaded to folder but in that folder file is not present.

Actually I tried your solution as a workout of my problem in which I am using pdfmake to make a pdf file and download but your download file also didn't worked so I think its an issue with ionic2.

I can't see any copied file

Hi,

I am new to ionic.
Did you test your project?
I got these errors when I build the project on Mac terminal.

home.ts(10,10): Error TS2339: Property 'platform' does not exist on type 'HomePage'
home.ts(11,10): Error TS2339: Property 'nav' does not exist on type 'HomePage'
home.ts(12,10): Error TS2339: Property 'image' does not exist on type 'HomePage'
home.ts(16,10): Error TS2339: Property 'platform' does not exist on type 'HomePage'
home.ts(17,32): Error TS2304: Cannot find name 'FileTransfer'
home.ts(18,32): Error TS2304: Cannot find name 'cordova'
home.ts(23,16): Error TS2339: Property 'platform' does not exist on type 'HomePage'.
home.ts(27,16): Error TS2339: Property 'platform' does not exist on type 'HomePage'.
home.ts(28,22): Error TS2304: Cannot find name 'cordova'.
home.ts(30,20): Error TS2339: Property 'platform' does not exist on type 'HomePage'.
home.ts(31,22): Error TS2304: Cannot find name 'cordova'.
home.ts(46,18): Error TS2339: Property 'nav' does not exist on type 'HomePage'.
home.ts(56,18): Error TS2339: Property 'nav' does not exist on type 'HomePage'.

I can launch this project on xCode but I can't see any copied files.

Can you help me?

Regards,

IOS

Have you had any issues where on IOS if you call the file its doesnt work? Did you have to use a cdvn file extension?

Image was not successfully download error code 3

I got an error message whenever i tried to run Image was not successfully download error code 3

the error message i print in the console is below:

body:
"↵AuthorizationQueryParametersErrorError parsing the X-Amz-Credential parameter; the Credential is mal-formed; expecting "<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request".C00E4770FE8ED94D0Hh2gcLDwzzRV2NypTaUleIwgxb7Pvp2gVYZCuHil/UWPTKZNBsocWGOY5Zr21ZGepmRBqgZhIU="
code:3
exception:null
http_status:400
source:
"https://uc-school-test.s3.ap-south-1.amazonaws.com/uploadedfiles/stu_achievements/Race.jpg?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI24P47A26KNEAK3Q%252F20180409%252Fap-south-1%252Fs3%252Faws4_request&X-Amz-Date=20180409T064429Z&X-Amz-SignedHeaders=host&X-Amz-Expires=604800&X-Amz-Signature=24ff112fd74d0ebcb9468913a2e47cdff6d71adac3c6a366541891dd74031af1"
target:null

when i remove the encodeURI error code 1 is shown

Download doesn't work on iOS

Hello,

I am using your app with ionic 2.2.1 and everything works just fine on Android, but fileTransfer.download() doesn't do anything on iOS, it just fails silently.

This issue is happening in my app where I'm using a similar method and I also tried it on yours and it neither works.

Property 'download' does not exist on type 'Transfer'.

Facing below error message:

Property 'download' does not exist on type 'Transfer'.

  L43:  		  fileTransfer.download(imageLocation, this.storageDirectory + image).then((entry) => {

[11:57:09] typescript: src/pages/home/home.ts, line: 71
Property 'checkFile' does not exist on type 'typeof File'.

  L71:      File.checkFile(this.storageDirectory, image)
  L72:        .then(() => {

Can you help me with this ?

Got an error when calling the upload, and no native function is called(i tried NSLog)

in the log, the path exists, and i used the File.checkFile

error is
{"line":951,"column":37,"sourceURL":"file:///var/containers/Bundle/Application/084ED2B6-958F-4206-94B2-322892B84A41/tongzhanbu.app/www/cordova.js"}
or
{"line":2,"column":xxx,"sourceURL":"file:///var/containers/Bundle/Application/084ED2B6-958F-4206-94B2-322892B84A41/tongzhanbu.app/www/build/polyfills.js"}
when the Transfer.upload.error

plz save me...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.