Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
TLove  
#1 Posted : Wednesday, December 31, 2014 11:26:24 AM(UTC)
TLove

Rank: Member

Groups: Member
Joined: 7/25/2007(UTC)
Posts: 17

Thanks: 3 times
Hi,

I am writing some JavaScript code to output the result of each upload only to find out that when an exception is thrown on the server, no other files are processed. Is the way it is supposed to work? If so, is there a way around this without having to fake the response code as a 200? It would really be helpful if there was a way to tell the uploader to continue processing the other files even when an error encountered. Each file upload package is it's own Ajax request that I would like to handle on a case by case basis.

I know there is an AfterPackageUpload event where you can return a boolean to control whether or not to continue, but this event is only fired on a successful upload. If I do pass back a response of 200 when there is an error the file item is removed from the pane and the user can't do a retry. They would have to go through the trouble of selecting the file again. It would be nice if there was an event that was called no matter what the response code was to allow this sort of behavior. I think I could live with forcing the server to return a response code of 200 if there was some way I could force the paneItem to remain in the upload pane.

Thank you for your time.
-Tim
Andrew  
#2 Posted : Friday, January 2, 2015 11:42:54 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Hi Tim,

Well, when the server returns an error code, the uploader stops by design. It is supposed that if the upload fails with 4xx or 5xx error, this is a bug in the application, i.e. it cannot be recovered. For example, if it receives 404, it means that wrong URL was specified as Action URL. Or if 500 error occurs, your server side application throws some unhandled exception and therefore it does not work as designed by you. I don't think that it is a good idea to ignore these errors and continue uploads as if the upload was complete successfully. Most likely your files was not saved on the server successfully and the user won't have any chance to know about it!

If you feel that the failure to save files is a valid behavior, you should not throw exception. Put your code into try/catch and return code 200 instead.

If you still prefer to throw code 500 from your server and continue uploading, you can add the Error event handler and call the $au.imageUploaderFlash('uploaderID').upload() method, although I would not recommend using such approach.

Hope this makes sense.
TLove  
#3 Posted : Monday, January 5, 2015 7:41:15 AM(UTC)
TLove

Rank: Member

Groups: Member
Joined: 7/25/2007(UTC)
Posts: 17

Thanks: 3 times
Hello Andrew,

Thank you for your response. I understand what you are saying and would agree if we were electing to use the uploader to send all the files in a single request. However, in this case I am sending each file as it's own request. On the server I am archiving the file into an imaging system. If this or any other process runs into an exception it might or might not affect subsequent requests. It was just a lot easier to just throw the exception and handle on a case by case basis rather than writing some extra code to capture that error and return a status of 200 along with an object that has a status of the upload. Like I said, I'm okay with that (as it doesn't seem like I have an alternative other than calling the upload method again), but I would still like to be able to have control over removing the panelItem.

I understand that I might be asking for too much as not everyone will be using the uploader the same way as I am. I really like your product, but more customization is always welcome.

Thank you for your time! I really appreciate it.
-Tim
Andrew  
#4 Posted : Tuesday, January 13, 2015 12:27:08 AM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Hi Tim,

I just realized that I missed this post. My apologies for a late answer.

Could you please clarify what you mean by "I would still like to be able to have control over removing the panelItem"? Do you mean you don't want it to be removed after the successful upload? Or vice versa, you want to be able to remove it from JavaScript?

If the latter, you can use $au.imageUploaderFlash('id').files().remove(i) method (where i is a number of an item in the upload list).

BTW, if you are applying some image processing operations on the uploaded files, I would recommend considering a kind of asynchronous approach - where you put uploaded files into a sort of queue and process this queue outside of the upload processing script. It would speed up the upload process significantly and solve this particular problem with exceptions (you would just display names of failed files somewhere else and let the users to decide if they want to reupload those files).

What you think?
thanks 1 user thanked Andrew for this useful post.
TLove on 1/13/2015(UTC)
TLove  
#5 Posted : Tuesday, January 13, 2015 4:38:18 AM(UTC)
TLove

Rank: Member

Groups: Member
Joined: 7/25/2007(UTC)
Posts: 17

Thanks: 3 times
Hi Andrew,

I ended up just capturing any recoverable errors on the server and returning the error in a json object to handle in JavaScript. That way I can continue with the other files.

I was actually looking to do the opposite and retain the item in the panel when an error occurred on the server. But I'm fine with the way I have it working now.

I'm not doing any processing on any of the files before uploading them thankfully as it makes the process much simpler. If we end up going down that route in the future I'll keep your suggestion in mind.

Thank you again for all of your help!
-Tim
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.