Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload accepting wrong file type #11

Open
fweffort opened this issue Nov 6, 2017 · 6 comments
Open

upload accepting wrong file type #11

fweffort opened this issue Nov 6, 2017 · 6 comments

Comments

@fweffort
Copy link

fweffort commented Nov 6, 2017

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

@sprmn
Copy link
Collaborator

sprmn commented Nov 9, 2017

@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.

@fweffort
Copy link
Author

fweffort commented Nov 9, 2017 via email

@sprmn
Copy link
Collaborator

sprmn commented Nov 10, 2017

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 #4 (comment). 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 sprmn closed this as completed Nov 10, 2017
@sprmn
Copy link
Collaborator

sprmn commented Nov 10, 2017

Whoops accidentally closed this issue. My bad

@sprmn sprmn reopened this Nov 10, 2017
@sprmn
Copy link
Collaborator

sprmn commented Nov 15, 2017

@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?

@comxd
Copy link

comxd commented May 4, 2020

Hi @sprmn , can you commit this new feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants