cinely / mule-uploader

Stubborn HTML5 Amazon S3 uploader
http://mule-uploader.com/
MIT License
223 stars 43 forks source link

Add support for cancelling upload in on_select #52

Closed Flynsarmy closed 9 years ago

Flynsarmy commented 9 years ago

This PR allows you to do stuff like:

on_select: function(fileObj) {
    if ( fileObj.name.match(/[a-zA-Z0-9\._-]+/g).length != 1 )
        throw "You can only upload filenames with letters, numbers, underscores and dashes. Please remove any quotes, spaces etc.";

    ....
}

This will make an error appear on upload in the same way one would appear if you didn't meet the file extension requirements.

gabipurcaru commented 9 years ago

Thanks for the help! I didn't have much time on my hands to merge PR's, but now I have a large-ish amount of time to fix stuff. I'm actually rewriting the library in ES6 right now, and I just incorporated your functionality on that branch (es6), with an adjustment: instead of throwing and catching errors, you have to return false in the callback.

Flynsarmy commented 9 years ago

I originally thought of returning false too, however its nice to be able yo send custom error messages, which throw let's you do. Otherwise you know an error occurred but have no idea what went wrong.

gabipurcaru commented 9 years ago

Well, you can always show an alert() before returning false. And you can also show your custom error message, so you have more options this way.