Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Read Chunked Data from Phone Gap File Upload in Android

We are trying to upload videos files from a phonegap mobile app to a web server. In iPhone everything works great, but on on Android the data is sent in chunks and our server app (php) is unable deal with it.

//phonegap 
var options = FileUploadOptions();
options.chunkedMode = true; //default

We tried turning chunkedMode to false. That works with smaller files by with any videos over 1mb the Android phone crashes. (that's the reason they turn chunkMode on by default).

Our question is how to read the uploaded chunk data using php? Is there a setting in Apache to that needs to be turned on to read this data?

like image 510
Charles Zhang Avatar asked Mar 03 '12 04:03

Charles Zhang


3 Answers

There's no difference between reading chunked data on the server side vs non-chunked. it's just the way the phone sends the data (in chunks of 8192 bytes, or as one stream).

There's a LOT of chatter around this feature on the web, and personally I've found the whole fileupload solution to be a bit flaky, especially on bigger files (for instance, video files).

Some people report it happens on files bigger than 4.8mb, on my android phone it happens around the 8mb mark.

When my app uploads files and there is no file attached (this is what happens in a connection error 3 scenario) i log it, so I can see the phones that are having issues. it happens with iphones too (certain models).

If you look at the android logs when it happens, you may well see an out of memory exception too.

How does this help you? it doesn't, really - but hopefully it helps explain what the problem is. Unfortunately there's not much we can do about it - apart from contributing to the phonegap source code and re-writing the filetransfer method!

Out of interest, on the phone you're having issues with, can you upload massive files using, say, facebook, without an issue? However that app is uploading files is surely the way that phonegap should be doing it..

like image 107
benpage Avatar answered Nov 20 '22 21:11

benpage


I've also experienced this issue. The file uploads fine in iOS, so the server is handling chunkedMode there, but on Android the fileupload returns "3" for connection error. I've tried the solution here: Phonegap : FileTransfer.upload() fails on Android, but no luck either.

like image 24
SilenceKit Avatar answered Nov 20 '22 20:11

SilenceKit


It ended being an webserver issue. Apache needs to be configured to support chunked mode. Also note that NGNIX does not have chunked mode support by default you would need to install a module http://wiki.nginx.org/HttpChunkinModule

like image 1
Charles Zhang Avatar answered Nov 20 '22 19:11

Charles Zhang