Tested on Android, Samsung Galaxy S, phonegap version: 1.3.0
I´m building a user based video uploader for a community.
All attempts using files less than 15 mb (roughly) works like a charm,
either if picking a file from the library or recording a video and
then uploading it.
I´ve tried this on two different servers with php ini settings well
above what is required.
I´ve tried chunkedMode = false;
Problem still remains, phonegap crashes if a video is larger than 15
mb. All files under 15 mb works really well.
Phonegap does not even return an error, it simply crashes.
I´ve tried putting in try catch statement without success.
Here is my code (very basic for testing purposes):
<!DOCTYPE html>
<html>
<head>
<title>Video Uploader</title>
<meta name="viewport" content="width=device-width, initial-
scale=1">
<link rel="stylesheet" href="master.css" type="text/css" />
<script type="text/javascript" charset="utf-8"
src="phonegap-1.3.0.js"></script>
<script type="text/javascript" charset="utf-8">
function onLoad() {
document.addEventListener("deviceready",onDeviceReady,false);
}
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function uploadFile(mediaFile,method) {
var ft = new FileTransfer(),
path = mediaFile,
name = "video.3gp";
var options = new FileUploadOptions();
options.chunkedMode = false;
options.fileKey = "file";
options.fileName = name;
options.mimeType = "video/mpeg";
ft.upload(path,
"http://www.myserver.com/upload.php",
function(r) {
alert('Success ' + r.response);
},
function(error) {
alert('Error ' + path + ': ' + error.code);
},
options);
}
function onPhotoURISuccess(imageURI) {
uploadFile(imageURI,"library");
}
function getVideo(source, type) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality:
50, destinationType: destinationType.FILE_URI, sourceType: source,
mediaType: type});
}
function onFail(message) {
alert('Error');
}
</script>
</head>
<body onload="onLoad()">
<button class="btn"
onclick="getVideo(pictureSource.PHOTOLIBRARY,Camera.MediaType.VIDEO);">Get
Video</button>
</body>
</html>
Any advice on this will be much appreciated!
Thanks!
You need to set
When chunked mode is false the HTTP code on Android tries to buffer the entire transfer in memory before sending. With larger transfers 15 mb in your case but for other phones it will be even less as they will have less memory this will cause an OutOfMemory Exception to be thrown. Since an OOME should never be caught the application will crash.
If you set chunked mode to true then the HTTP code on Android attempts to use streaming mode to send the info to the server. Not all servers support the streaming mode but most do.
As to why it fails at 40+ mb I’m at a bit of a loss unless you php.ini file specifies this is the largest file size it will accept.