cordova-plugin-file-transfer icon indicating copy to clipboard operation
cordova-plugin-file-transfer copied to clipboard

Downloaded file got in 0 Bytes

Open sachinbasendr opened this issue 5 years ago • 11 comments

Using Ionic 3.20.1 and node 10.16.3 android platform let uri = 'server url using https'; let dir = this.file.externalRootDirectory+'AppName/Documents/'; this.platform.ready().then(() => { const fileTransfer: FileTransferObject = this.transfer.create(); fileTransfer.download(uri,dir+'filename.pdf').then((entry: Entry) => { var fileEntry = entry as FileEntry; console.log(fileEntry); }, (error) => { }); });

My file has been downloaded but got 0 Bytes size I don't know what happen? i am using these versions "@ionic-native/file": "^4.20.0", "@ionic-native/file-chooser": "^4.18.0", "@ionic-native/file-opener": "^4.20.0", "@ionic-native/file-path": "^4.20.0", "@ionic-native/file-picker": "^4.18.0", "@ionic-native/file-transfer": "^4.20.0", Please help

sachinbasendr avatar Nov 06 '19 12:11 sachinbasendr

Use the error callback to determine if there was an error that occurred. If so, please include that information.

breautek avatar Nov 06 '19 13:11 breautek

Also please do not remove the bug template. It's there for a reason and filling out the form properly will give us much more information about your environment. So do please edit your question and fill it out.

breautek avatar Nov 06 '19 13:11 breautek

Hi @breautek There are no any error occurred in callback, i got success callback function

My environments cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.3
ionic (Ionic CLI) : 3.20.1

global packages:

cordova (Cordova CLI) : 7.1.0 

local packages:

@ionic/app-scripts : 3.2.0
Cordova Platforms  : android 7.1.4
Ionic Framework    : ionic-angular 3.9.9

System:

Android SDK Tools : 26.1.1
Node              : v10.16.3
npm               : 6.9.0 
OS                : Linux 4.15

Environment Variables:

ANDROID_HOME : /home/flitwebs/Android/Sdk

Misc:

backend : pro

Thanks for the reply @breautek .

sachinbasendr avatar Nov 07 '19 09:11 sachinbasendr

Hello @breautek ,

I just use download URL server from any other source then it was successfully downloaded with correct size. So u can tell me what was wrong with my download server URL.

Thanks @breautek Please help

sachinbasendr avatar Nov 07 '19 09:11 sachinbasendr

So u can tell me what was wrong with my download server URL.

That's going to be really hard to answer. Could be the server sending incorrect Content-Type or Content-Length, the server could be running into an error and not sending the entire file, etc. The possibilities is endless... If the problem is indeed with your server, you'll have to login to it and look at the logging information, or update the server to produce debugging output, etc.

breautek avatar Nov 07 '19 15:11 breautek

@sachinbasendr How are you serving the file from your server? If you are doing it via a pipe, then it might not work (from what I've noticed). You may have to send the complete file at once. Maybe if you can show your server code, I might be able to help out. Cheers

ibesoft11 avatar Nov 26 '19 11:11 ibesoft11

I have the same issue with a Cordova app for iOS tested on iPhone XR 13.3.1

The server returns the correct Content-Type and Content-Lenght.

I tried all examples here https://cordova.apache.org/docs/en/6.x/reference/cordova-plugin-file-transfer/index.html and always I received successful result, but file is 0 KB. File trasfer in fact is too fast to complete, it does not wait for file generation on server.

Something related to https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html ?

Installed platforms: ios 5.1.1

Plugins cordova-plugin-file 6.0.2 "File" cordova-plugin-file-opener2 3.0.0 "File Opener2" cordova-plugin-file-transfer 1.7.1 "File Transfer" cordova-plugin-inappbrowser 3.2.0 "InAppBrowser" cordova-plugin-splashscreen 5.0.3 "Splashscreen" cordova-plugin-whitelist 1.3.4 "Whitelist" cordova-plugin-wkwebview-engine 1.2.1 "Cordova WKWebView Engine"

GioviQ avatar Feb 09 '20 08:02 GioviQ

I have the same problem. On android it's working fine but on IOS the downloaded file has 0 Bytes size using the same http service to download the file. Anybody has a solution?

OFMaurice avatar Nov 25 '21 09:11 OFMaurice

I have the same problem. On android it's working fine but on IOS the downloaded file has 0 Bytes size using the same http service to download the file. Anybody has a solution?

I found the problem on IOS my cookies are not sent with the download request

OFMaurice avatar Nov 25 '21 10:11 OFMaurice

I have the same issue on Android running Ionic. I have a podcast application that downloads episodes, and although most work well, some podcasts return a success, but have a file size of 0 bytes. Both links are downloadable in the browser though.

Example of good URL: https://www.listennotes.com/e/p/54bb560d1a9e4ac1836662ee2c469030/

Example of 0 byte issue: https://www.listennotes.com/e/p/8685f19b77874283a0b6e159eb7024ea/

UPDATE - 31 Jan 2022

I solved my issue on Android. I tested today on IOS, which worked fine, and since the above links work on a browser, I had a deeper look at Android. Both above links have redirects, which is handled fine by IOS. Turns out that Android java redirects using HttpURLConnection only work when the redirect protocol remains the same over each hop i.e. all http, or all https (by design, apparently for security reasons). In my case, the 'bad url' had multiple redirects, with a mix of protocols. So it stops when the protocol changes, and hence the file you download is the 302 redirect page where it changed, and hence you get a successful download, but with a file that is 0 bytes.

My workaround is to add some code that manually follows the directs.

ShaunBrassell avatar Jan 04 '22 10:01 ShaunBrassell

I also encountered this problem, how to solve it?

malgee012 avatar Dec 26 '23 06:12 malgee012