Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Cordova File Upload Plugin

Hi,

I've added the cordova file upload plugin to my app and using the demo page I can successfully upload photos taken by the camera to my files database.

However, if I change the setting to take photos from the photo library/gallery, it does not upload the photo despite giving me the "File Uploaded" alert.
It also leaves the Image URL as undefined (so it's not getting the response from the service to give the URL either).

Can you tell me what is wrong please?

regards

Andy

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Cordova File Upload Plugin

Hello Andy,

Please add a test alert to the success event of that service:
prealert(JSON.stringify(data));/pre
Kindly let us know the result.

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Cordova File Upload Plugin

Thanks Sergiy
Here's the reply:
DBFM 151: Invalid filename was used, a valid filename contains.....

So, I check what was being passed as the URI, here's an example:

file:///storage/emulated/0/Android/data/io.appery.tester/cache/modified.jpg?1464260683581

No matter what image I try, I get the same error.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Cordova File Upload Plugin

Please check the same on the native app, installed on the device, instead of Appery.io tester app.

Also, please check the file with a simple name, e.g. 1.jpg

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Cordova File Upload Plugin

ok, compiled to APK and loaded on to device.

First test: try random image upload.
Result: Failed,same error as before.
URI: file:///storage/emulated/0/Android/data/io.appery.project405064/cache/modified.jpg?1464271226784

Second test was with an image that I renamed to 1.jpg, exactly the same result, it seems that the file is moved and renamed prior to upload.....

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Cordova File Upload Plugin

ok, so I've got it working by modifying the FileUploadHelper function UploadPhoto.

code
if (imageURI.indexOf("?")>0) {
//
// here is photo is from library - decode filename and file extension
//
var imageType = imageURI.substring(imageURI.lastIndexOf('.'),imageURI.lastIndexOf('?'));
var imageName = imageURI.substring(imageURI.lastIndexOf('?')+1);
} else {
//
// here if file from camera
//
var imageType = imageURI.substring(imageURI.lastIndexOf('.'));
var imageName = imageURI.substring(imageURI.lastIndexOf('/')+1,imageURI.lastIndexOf('.'));
}
// var imageType = imageType1.substr(imageURI.lastIndexOf('.')+1);
var options = $.extend(new FileUploadOptions(), reqOptions);

Code: Select all

     if(imageName) { 
         options.fileName = imageName + imageType; 
         options.fileKey= imageName + imageType; 
     } else { 
         options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1); 
         options.fileKey = imageURI.substr(imageURI.lastIndexOf('/')+1); 
     } 

/code

Basically, I've pulled out the correct filename from the string reported by the URI depending on whether the image is from the camera or a gallery photo.
Maybe this is only happening on Android Marshmallow? I'm testing on a Nexus 6P currently.

Galyna Abramovych
Site Admin
Posts: 84
Joined: Tue Mar 22, 2016 6:03 pm

Cordova File Upload Plugin

Hello Andy,

Thank you for update here.
Please, report if you experience a similar issue on other devices.

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Cordova File Upload Plugin

Same issue with Samsung Galaxy S4 running Android 5.0.1.

My fix works on this device as well.

regards

Andy.

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Cordova File Upload Plugin

Not an issue however on iPhone 6s....strange.

However, my code still works on all devices.

Galyna Abramovych
Site Admin
Posts: 84
Joined: Tue Mar 22, 2016 6:03 pm

Cordova File Upload Plugin

Dear Andy,

Thank you again for having shared your development experience!

Return to “Issues”