Adrian Stoch
Posts: 0
Joined: Thu Jul 31, 2014 3:09 pm

File Upload error: TypeError Illegal invocation

My file upload function was previously working fine, but now I am getting the following error when invoking the service to upload a file:
TypeError Illegal invocation

Here is my mapping of the request service:
Image

The user is logged on and I have a valid session token:
Image

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

File Upload error: TypeError Illegal invocation

Hi Adrian,

Unfortunatly that's a bug. We working on it.

But here is a quick workauround for you:

1 Create JS asset:.

2 Populate it with following code:

pre

function uploadMultipleFilesHelperNew(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 = item&#46;name; 
         } 
         formData&#46;append(name, item); 
     } 
 } 

}

/pre

  1. Ok, now you can use "uploadMultipleFilesHelperNew" instead of "uploadMultipleFilesHelper".

    Regards.

Adrian Stoch
Posts: 0
Joined: Thu Jul 31, 2014 3:09 pm

File Upload error: TypeError Illegal invocation

Thanks Yurii,

The temporary work around seems to do the trick. Is it possible to be notified when the bug is fixed so I can revert to the standard?

Thanks

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

File Upload error: TypeError Illegal invocation

He Adrian,

Yeap, we will update you here as soon as we will fix this bug.

Regards.

Joseph Francis
Posts: 0
Joined: Thu Sep 04, 2014 8:52 pm

File Upload error: TypeError Illegal invocation

I have the same problem, but when using the new upload function I get the following error: "400 bad request", with the sub-message "

{"code":"BCXX002","description":"Cannot consume content type"}

Nothing has changed in my code to upload files, and at this point all file uploading functions in my application are dead.

Adrian Stoch
Posts: 0
Joined: Thu Jul 31, 2014 3:09 pm

File Upload error: TypeError Illegal invocation

Joseph, try implementing Yurii's JS asset above. I believe there is a current bug with the file upload function that they are working on. I was dead until I implemented the above fix and the function works fine now.

I must say though that the communication of this issue from Appery has not been stellar.

Joseph Francis
Posts: 0
Joined: Thu Sep 04, 2014 8:52 pm

File Upload error: TypeError Illegal invocation

Adrian, thanks for the update - I implemented the ..New function per above and no I no longer get the TypeError - but file upload craps out with the "cannot consume content".

Were you able to get it work? I'm into market testing for my app today, and I've had to disable all image uploading for the moment.

Adrian Stoch
Posts: 0
Joined: Thu Jul 31, 2014 3:09 pm

File Upload error: TypeError Illegal invocation

Joseph, I just tested upload function on my browser (Chrome) and iphone appery app. Both seem to be working fine using the above fix that addressed the "TypeError" problem.

I believe that my issue with the "cannot consume content" had to do with the service mapping. Something had caused the previously working service to become corrupted. I can only suggest that you double check your service mappings and even remove them from the page and then add back. It may be painful as you'll have to manually redo the mappings, but I think that's what fixed it for me.

Best of luck.

Joseph Francis
Posts: 0
Joined: Thu Sep 04, 2014 8:52 pm

File Upload error: TypeError Illegal invocation

Thanks Adrian, I will try now.

Return to “Issues”