Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

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

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.

xman
Posts: 0
Joined: Sun Jul 06, 2014 7:05 pm

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

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.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

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

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.

xman
Posts: 0
Joined: Sun Jul 06, 2014 7:05 pm

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

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"

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

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

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.

xman
Posts: 0
Joined: Sun Jul 06, 2014 7:05 pm

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

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.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

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

Hi Xman,

Thanks for your update.

Yes we will help you on that thread.

Regards.

Yang Mega
Posts: 0
Joined: Sun Aug 31, 2014 6:08 am

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

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
Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

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

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

Return to “Issues”