3

I am attempting to get a video file on android, convert it to base64 encoding and upload it.

When the file is larger than 5Mb, I get out of memory error in android, but ios convert large files also. Only in android I got this error....

This is my code:

var reader = new FileReader();
reader.onload = function(evt1) {}, reader.onloadend = function(evt) {
    console.log("read success");
    console.log(evt.target.result);
};
reader.readAsDataURL(file);
Kathir
  • 4,359
  • 3
  • 17
  • 29

2 Answers2

7
  1. You should be aware that the base64-encoded data will be roughly 37% larger than the original data size. Considering that you're dealing with large files and the base64-encoding causes out of memory errors, I would not encode it with base64.

  2. It's not a good idea to read large files at once. Instead, I recommend streaming your file to the server. With this approach, the file will be read and transferred in chunks, preventing out of memory errors and avoiding lags on slower devices. You can do this for example using the FileTransfer object with chunkedMode enabled in the FileUploadOptions.

Recommended approach (adapted from the documentation):

// !! Assumes variable fileURI contains a valid URI to a H.264/AVC video on the device

var win = function (r) {
    console.log("Code = " + r.responseCode);
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent); }

var fail = function (error) {
    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target); }

var options = new FileUploadOptions();
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = "video/avc"; //change to the according mimeType
options.chunkedMode = true; //upload the data in chunked streaming mode (true by default)

var ft = new FileTransfer();
ft.upload(fileURI, encodeURI("http://some.server.com/upload.php"), win, fail, options);
Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
1

create php.ini file on server side and add following code. You can increase upload_max_filesize

register_globals = on

display_errors = Off

error_reporting = E_ALL & E_NOTICE & E_WARNING & E_DEPRECATED

upload_max_filesize = 50M

memory_limit = 500M

max_execution_time = 1800

post_max_size = 120M

session.gc_maxlifetime = 86400

error_log = /var/log/php-scripts.log

#safe_mode = Off #safe_mode_exec_dir = "storage_dir_path" #open_basedir = "storage_dir_path"
Ved
  • 2,701
  • 2
  • 22
  • 30
  • i am not using file upload concepts in phonegap. i am convert base64 string and send data(base64 string) to server using jquery ajax post. i got error in video to base64 convertion error...... – Kathir Apr 12 '14 at 07:11