Diego Murru
Posts: 0
Joined: Fri Apr 04, 2014 2:58 pm

transfer a file from library to external server

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?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

transfer a file from library to external server

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

Diego Murru
Posts: 0
Joined: Fri Apr 04, 2014 2:58 pm

transfer a file from library to external server

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.

Diego Murru
Posts: 0
Joined: Fri Apr 04, 2014 2:58 pm

transfer a file from library to external server

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

transfer a file from library to external server

Hello!

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

Diego Murru
Posts: 0
Joined: Fri Apr 04, 2014 2:58 pm

transfer a file from library to external server

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

transfer a file from library to external server

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

Diego Murru
Posts: 0
Joined: Fri Apr 04, 2014 2:58 pm

transfer a file from library to external server

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

Diego Murru
Posts: 0
Joined: Fri Apr 04, 2014 2:58 pm

transfer a file from library to external server

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

Thanks
Diego

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

transfer a file from library to external server

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

Return to “Issues”