johndatserakis / file-upload-with-preview

🖼 Simple file-upload utility that shows a preview of the uploaded image. Written in TypeScript. No dependencies. Works well with or without a framework.

Home Page:https://johndatserakis.github.io/file-upload-with-preview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MAX_FILE_SIZE is not working.

chayut27 opened this issue · comments

I'm sorry, but I'm asking how to use it. MAX_FILE_SIZE is not working.

I can add images greater than 2mb.

Hi there - MAX_FILE_SIZE is not something that is going to stop users from selecting files over the given amount, unfortunately.

I don't believe that is possible on the frontend. The only restrictions you can have is on file type (extension). The problem is browsers don't listen to the setting.

To prevent users from uploading files over a certain size, you'll need to:

  1. Check on the backend when you go to upload the files to your server. Long ago, I used PHP - and MAX_FILE_SIZE was something you could add to your inputs to give a certain error when uploading. But unless you're using PHP, this won't do anything. I'll probably remove it from the HTML code block at some point. Sorry for the confusion.

Or

  1. You could hook into the fileUploadWithPreview:imagesAdded event and take a look at the image that was uploaded and remove it from the cachedFileArray. That would probably be what I do.