How to Read Chunked Data from Phone Gap File Uploa

2019-04-07 13:10发布

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?

4条回答
Rolldiameter
2楼-- · 2019-04-07 13:24

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..

查看更多
迷人小祖宗
3楼-- · 2019-04-07 13:29

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

查看更多
Ridiculous、
4楼-- · 2019-04-07 13:30

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.

查看更多
仙女界的扛把子
5楼-- · 2019-04-07 13:31

Another odd observation. I uploaded a 50MB video file to the wrong URL. It went nowhere, but Android spun it's wheels for a few minutes and triggered the success callback. No error 3 and no crashing. Once I fixed the typo and submitted to the correct URL, I got error 3.

查看更多
登录 后发表回答