asafdav / ng-s3upload

Upload to S3 using AngularJS
MIT License
190 stars 83 forks source link

accept restrictions #12

Open neekers opened 10 years ago

neekers commented 10 years ago

Another attribute could be "accept" to limit file types.

davidstanley01 commented 9 years ago

I added an "allowedOptions" key to the s3UploadOptions object to contain an array of acceptable MIME types. Then, I added the following to the directive at line 62.

if (opts.allowedTypes) {
   if (opts.allowedTypes.indexOf(selectedFile.type) === -1) {
       throw Error("Invalid MIME type");
   }
}

This works for me. I'd be happy to put it in a pull request...

asafdav commented 9 years ago

Hi, looks good. Please send a pull request. also please note that currently your code doesn't handle a case where the file's MIME type couldn't be determined. (file.type would return an empty string in that case). you can convert it into application/octet-stream before performing your test.

davidstanley01 commented 9 years ago

No problem. I'll send it over tonight or tomorrow. Thanks!