react-firebase-file-uploader icon indicating copy to clipboard operation
react-firebase-file-uploader copied to clipboard

upload accepting wrong file type

Open fweffort opened this issue 8 years ago • 6 comments

if you open the file selector and change to ., and then choose a zip for instance, it will fail validation and upload anyway. is there any way to fix this

fweffort avatar Nov 06 '17 17:11 fweffort

@fweffort thanks for opening this issue. I will try to look into it this weekend. I guess you could already fix this by overwriting the onChange function and calling the startUpload function manually in a similar way as suggested here. If you check the MIME type in the onChange function, you can determine whether or not you'd like to call the startUpload function or present a warning/error to the user. I'm planning on adding the possibility to perform some checks or preprocessing before files are uploaded. There should be a way to cancel the upload in these functions.

sprmn avatar Nov 09 '17 08:11 sprmn

I cannot update this, as I am hosting it in firebase, and on deploy firebase will download your code again and will use yours instead of mine.

but please, keep me updated when I can use this.

I really like the way it runs. suits my application very well.

thanks!!

Em 9 de nov de 2017 06:48, "Frank van der Hoek" [email protected] escreveu:

@fweffort https://github.com/fweffort thanks for opening this issue. I will try to look into it this weekend. I guess you could already fix this by overwriting the onChange function and calling the startUpload function manually in a similar way as suggested here https://github.com/sprmn/react-firebase-file-uploader/issues/4#issuecomment-277352083. If you check the MIME type in the onChange function, you can determine whether or not you'd like to call the startUpload function or present a warning/error to the user. I'm planning on adding the possibility to perform some checks or preprocessing before files are uploaded. There should be a way to cancel the upload in these functions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sprmn/react-firebase-file-uploader/issues/11#issuecomment-343086627, or mute the thread https://github.com/notifications/unsubscribe-auth/AfvpYgQtlQonGR-psOPf__Gj9nzNv_ayks5s0rxWgaJpZM4QTmST .

fweffort avatar Nov 09 '17 16:11 fweffort

Oo, but you don't have to edit my code at all. The fix I'm suggesting is no change in this library, just a change in the code on your side. See https://github.com/sprmn/react-firebase-file-uploader/issues/4#issuecomment-277352083. But of course you could also wait for me to fix it in the lib. Can't promise I'll have it fixed this weekend though.

sprmn avatar Nov 10 '17 14:11 sprmn

Whoops accidentally closed this issue. My bad

sprmn avatar Nov 10 '17 14:11 sprmn

@fweffort I added a new functionality in the preprocessing branch. You can now add a beforeUploadStart property which allows you to reject uploads if for example the file type is incorrect.

To try it you'll have to install this branch temporarily using:

npm i sprmn/react-firebase-file-uploader#preprocessing

If you want to use the new feature you'll have to provide the beforeUploadStart prop as follows:

<FileUploader
  beforeUploadStart={file => { if (!/^image\/.*/.test(file.type)) throw Error('Invalid type') }}
  [other props]
/>

Can you please confirm that it works for you?

sprmn avatar Nov 15 '17 13:11 sprmn

Hi @sprmn , can you commit this new feature?

comxd avatar May 04 '20 15:05 comxd