Page 1 of 2

transfer a file from library to external server

Posted: Tue Aug 05, 2014 4:38 pm
by Diego Murru

I can not transfer a video file from the smartphone library to my server.

I'm using this code, but I can not pass the FILE_URI to transfer function.

code
var cameraSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles&#46;length; i < len; i += 1) {
uploadFile(mediaFiles);

&#47;&#47; do something interesting with the file
}
};
&#47;&#47; capture error callback
var cameraError = function(error) {
navigator&#46;notification&#46;alert('Error code: ' + error&#46;code, null, 'Capture Error');
};
&#47;&#47; start video capture
navigator&#46;camera&#46;getPicture(cameraSuccess, cameraError, {
destinationType: Camera&#46;DestinationType&#46;FILE_URI,
sourceType: navigator&#46;camera&#46;PictureSourceType&#46;PHOTOLIBRARY,
mediaType: navigator&#46;camera&#46;MediaType&#46;VIDEO });

&#47;&#47; Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile&#46;fullPath,
name = mediaFile&#46;name;
Appery("nomeVideo")&#46;text(name);

Code: Select all

  ft&#46;onprogress = function(result){ 
  var percent =  result&#46;loaded / result&#46;total * 100; 
  percent = Math&#46;round(percent); 
  Appery('progressbar')&#46;text('Upload:  ' + percent + '%');     
  }; 

     ft&#46;upload(path, 
               "http:&#47;&#47;www&#46;xxx&#46;com/uploadVideo/index&#46;php", 
               function(result) { 
               alert('Upload success: ' + result&#46;responseCode); 
               console&#46;log(result&#46;bytesSent + ' bytes sent'); 
               }, 
               function(error) { 
               alert('Error uploading file ' + path + ': ' + error&#46;code); 
               }, 
               { fileName: name }); 

 } 

/code

Can you help me?


transfer a file from library to external server

Posted: Tue Aug 05, 2014 5:31 pm
by Evgene Karachevtsev

Hello Diego,

You can use the camera (http://devcenter.appery.io/tutorials/...) with parameter
presourceType = PHOTOLIBRARY/pre
Please find more info here: http://docs.phonegap.com/en/3.3.0/cor...


transfer a file from library to external server

Posted: Tue Aug 05, 2014 5:41 pm
by Diego Murru

Hi

i need to transfer only video file, and upload it to external server (not Appery Database).

With my code i can select the video file from the library, but the transfert part don't work.


transfer a file from library to external server

Posted: Tue Aug 05, 2014 5:43 pm
by Diego Murru

the file transfer, work when i use the capture function, but don't work when i try to select a file from library with this code.


transfer a file from library to external server

Posted: Wed Aug 06, 2014 9:15 am
by Maryna Brodina

Hello!

Are there any errors in console? What device you use to test?


transfer a file from library to external server

Posted: Wed Aug 06, 2014 10:58 am
by Diego Murru

Hi Maryna

the only error is this:

code
Uncaught TypeError: Cannot read property 'getPicture' of undefined
$&#46;off&#46;on&#46;click
jQuery&#46;event&#46;dispatch jquery-1&#46;9&#46;1&#46;js:3074
elemData&#46;handle
/code

i tested it a on Android Galaxy S4. The fileTranfert code work when i capture the video and upload it on the server.

but does not work when I choose a video file from library. I think the problem is in the file_uri passage. I've tried other code and i follow the phonegap official tutorial, without success.


transfer a file from library to external server

Posted: Thu Aug 07, 2014 7:41 am
by Maryna Brodina

Hello!

1) So in your code you change sourceType and it works? Or you also changed something else?

preUncaught TypeError: Cannot read property 'getPicture' of undefined/preThis error means you call the code before Device ready event

2) Try this code, but run it after device ready event

prevar cameraSuccess = function(mediaFiles) {
alert(JSON&#46;stringify(mediaFiles));
};
&#47;&#47; capture error callback
var cameraError = function(error) {
navigator&#46;notification&#46;alert('Error code: ' + error&#46;code, null, 'Capture Error');
};
&#47;&#47; start video capture
navigator&#46;camera&#46;getPicture(cameraSuccess, cameraError, {
destinationType: Camera&#46;DestinationType&#46;FILE_URI,
sourceType: navigator&#46;camera&#46;PictureSourceType&#46;PHOTOLIBRARY,
mediaType: navigator&#46;camera&#46;MediaType&#46;VIDEO
});/pre


transfer a file from library to external server

Posted: Thu Aug 07, 2014 8:27 am
by Diego Murru

Hi

I changed the code, but the file transfer does not work. I can select the file from the library, but this is not sent to my server.

code
var cameraSuccess = function(mediaFiles) {
alert(JSON&#46;stringify(mediaFiles));
};
&#47;&#47; capture error callback
var cameraError = function(error) {
navigator&#46;notification&#46;alert('Error code: ' + error&#46;code, null, 'Capture Error');
};
&#47;&#47; start video capture
navigator&#46;camera&#46;getPicture(cameraSuccess, cameraError, {
destinationType: Camera&#46;DestinationType&#46;FILE_URI,
sourceType: navigator&#46;camera&#46;PictureSourceType&#46;PHOTOLIBRARY,
mediaType: navigator&#46;camera&#46;MediaType&#46;VIDEO
});

&#47;&#47; Upload files to server
function uploadFile(mediaFiles) {
var ft = new FileTransfer(),
path = mediaFiles&#46;fullPath,
name = mediaFiles&#46;name;
Appery("nomeVideo")&#46;text(name);

Code: Select all

  ft&#46;onprogress = function(result){ 
  var percent =  result&#46;loaded / result&#46;total * 100; 
  percent = Math&#46;round(percent); 
  Appery('progressbar')&#46;text('Upload:  ' + percent + '%');     
  }; 

     ft&#46;upload(path, 
               "http:&#47;&#47;www&#46;xxx&#46;com/uploadVideo/index&#46;php", 
               function(result) { 
               alert('Upload success: ' + result&#46;responseCode); 
               console&#46;log(result&#46;bytesSent + ' bytes sent'); 
               }, 
               function(error) { 
               alert('Error uploading file ' + path + ': ' + error&#46;code); 
               }, 
               { fileName: name }); 

 } 

/code


transfer a file from library to external server

Posted: Fri Aug 08, 2014 9:16 am
by Diego Murru

I've tried other changes but without success...
you can help me?

Thanks
Diego


transfer a file from library to external server

Posted: Fri Aug 08, 2014 3:31 pm
by Evgene Karachevtsev

Hello Diego,

Could you please clarify, are there any errors in the console when you send a file? Could you please look through Weinre: http://devcenter.appery.io/documentat...