Page 1 of 1

Cordova File Upload Plugin

Posted: Wed May 25, 2016 11:32 am
by Andy Parker

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


Cordova File Upload Plugin

Posted: Thu May 26, 2016 9:55 am
by Serhii Kulibaba

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.


Cordova File Upload Plugin

Posted: Thu May 26, 2016 11:06 am
by Andy Parker

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.


Cordova File Upload Plugin

Posted: Thu May 26, 2016 12:41 pm
by Serhii Kulibaba

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


Cordova File Upload Plugin

Posted: Thu May 26, 2016 2:05 pm
by Andy Parker

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


Cordova File Upload Plugin

Posted: Thu May 26, 2016 4:16 pm
by Andy Parker

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.


Cordova File Upload Plugin

Posted: Thu May 26, 2016 4:20 pm
by Galyna Abramovych

Hello Andy,

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


Cordova File Upload Plugin

Posted: Thu May 26, 2016 4:34 pm
by Andy Parker

Same issue with Samsung Galaxy S4 running Android 5.0.1.

My fix works on this device as well.

regards

Andy.


Cordova File Upload Plugin

Posted: Thu May 26, 2016 4:37 pm
by Andy Parker

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

However, my code still works on all devices.


Cordova File Upload Plugin

Posted: Thu May 26, 2016 8:40 pm
by Galyna Abramovych

Dear Andy,

Thank you again for having shared your development experience!