Page 7 of 8

How to add custom "File Name" to an image/file being uploaded?

Posted: Sun Oct 19, 2014 10:37 pm
by Yurii Orishchuk

Hi Xman,

Please use following JS code:

pre

function uploadMultipleFilesHelperWithCustomName(datasource, fileList) {
var isCorrectService = false;
if (datasource) {
if (datasource.service && datasource.service.requestOptions) {
var options = datasource.service.requestOptions;
isCorrectService = options.type === 'post' && options.contentType === false && /^.*\/files$/i.test(options.url);
}
}
if (isCorrectService) {
if (fileList) {
var data = new FormData();
for (var i = 0; i < fileList&#46;length; i++) {
appendItem(data, fileList);
}
try {
datasource&#46;execute({
'allowDataModification': false,
'processData': false,
'body': {data: data},
'cache': false
});
} catch (exception) {
console&#46;log(exception&#46;name + ' ' + exception&#46;message);
hideSpinner();
}
}
} else {
console&#46;warn('This data source not be supported in the method of upload multiple files');
}

Code: Select all

 function appendItem(formData, item) { 
     if (item) { 
         if (item&#46;type === 'file') { 
             item = item&#46;files; 
         } 
         if (item instanceof FileList) { 
             for (var i = 0; i < item&#46;length; i++) { 
                 appendItem(formData, item[i]); 
             } 
             return; 
         } 
         var name; 
         if (item&#46;name) { 
             name = "customPart_" + item&#46;name; 
         } 
         formData&#46;append(name, item); 
     } 
 } 

}

/pre

Also don't forget check links in mapping.

Regards.


How to add custom "File Name" to an image/file being uploaded?

Posted: Mon Oct 20, 2014 5:00 am
by xman

Hi Yurii, that is exactly the script you provided me previously.

It was working fine until the platform update. After that this script when executes give me "illegal invocation" in the debug tools console log in the browser (and nothing happens). I am not sure what happened after the platform update to cause this script to start behaving like this.


How to add custom "File Name" to an image/file being uploaded?

Posted: Mon Oct 20, 2014 9:07 pm
by Yurii Orishchuk

Hi Xman,

That's not exactly the same script i provided you above in this thread.

So you can use it and it should work.

Regards.


How to add custom "File Name" to an image/file being uploaded?

Posted: Mon Oct 20, 2014 9:24 pm
by xman

Thanks Yurii, I just saw the difference!
So I replaced the previous JS with this new one, now when I select the file and click my upload button I get the following alert/error popup on screen:

"Cannot consume content type"


How to add custom "File Name" to an image/file being uploaded?

Posted: Tue Oct 21, 2014 2:17 am
by Yurii Orishchuk

Xman,

Please try to use following settings for your upload service:

  1. Headers: http://prntscr.com/4y6zbx/direct

  2. "Query string": http://prntscr.com/4y6zoh/direct

  3. "Body": http://prntscr.com/4y6zu8/direct

    Regards.


How to add custom "File Name" to an image/file being uploaded?

Posted: Mon Oct 27, 2014 1:49 am
by xman

Thanks Yurii that worked - looks like the requirement on the request had changed the previously working body/header was not functional anymore.

I have found another issue that started showing up after the update:https://getsatisfaction.com/apperyio/...

If you can help there as well it will be great.


How to add custom "File Name" to an image/file being uploaded?

Posted: Mon Oct 27, 2014 11:19 pm
by Yurii Orishchuk

Hi Xman,

Thanks for your update.

Yes we will help you on that thread.

Regards.


How to add custom "File Name" to an image/file being uploaded?

Posted: Sat Nov 01, 2014 6:04 pm
by Yang Mega

Image

I have tested the this issue, I found two bugs

  1. while I did not select any file to upload, service still success and alert success after click the upload button
  2. While test in Appery tester on mobile, the uploadfile button doesn't work
    Image

How to add custom "File Name" to an image/file being uploaded?

Posted: Sun Nov 02, 2014 2:10 pm
by Illya Stepanov

As you can see it's a temporary workaround solution, this bug will be fixed in next Appery.io release update.


How to add custom "File Name" to an image/file being uploaded?

Posted: Mon Nov 03, 2014 7:15 pm
by Maryna Brodina

Hello!

This post might help https://getsatisfaction.com/apperyio/...