Reputation: 23
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!
Upvotes: 2
Views: 8687
Reputation: 23273
You need to set
options.chunkedMode=true;
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.
Upvotes: 4
Reputation: 5267
Have you tried printing out any debug statements on your PHP script just to see what is going wrong?
Your client code looks fine and I am using almost identical code without any problems. I have been able to upload video files of around 40MB with the PhoneGap FileTransfer object.
Another option might be to create a copy of the FileTransfer as your custom plugin. You can then put a breakpoint in the Java code to see what is going wrong.
Sorry I can't be any more help since it just worked for me!
Upvotes: 0