1

so I have this standard input file code

<Label class="custom-file-upload">
   <input type="file" onChange={onDrop} />
   Upload Photo
</Label>

I want to limit the size of the file the user can upload which I can obviously do with javascript. but I was wondering if there is any way to decide the image size for them so to speak

I've noticed when I've been testing when I choose an image it's 3.8mb but on my iPhone I can do Choose Image Size and when I chose large (the biggest option) it said the image was 562kb which is crazily smaller and perfect for me. I don't want to be storing images bigger than I need for obvious reasons

Like I said, I know I could validate this but I fear users (especially non tech users) might bounce or not upload if they're told the image is too big. I know it's a stretch but it would be good if there was a way to influence this somehow

let me know if possible

Red Baron
  • 7,181
  • 10
  • 39
  • 86
  • this might help https://stackoverflow.com/questions/3717793/javascript-file-upload-size-validation – Nishant Jun 19 '20 at 12:34
  • I guess they're kind of similar. one thing that would be nice with those similar questions, is it possible to get the user to choose a photo again rather than having to click `Upload Photos` again? i.e. it takes them back to their photo albums – Red Baron Jun 19 '20 at 12:41
  • guess I'm just gonna have to do compression after upload aren't I ! ok thanks everyone – Red Baron Jun 19 '20 at 12:48

1 Answers1

1

AFAIK there is no such API. And I agree that it could be frustrating for non-tech users to be told the image is too large. An option you could consider is to take whatever users selected and resize it on the client-side using this library - pica. It has pretty good browser support and it makes use of web workers or WebAssembly.

hangindev.com
  • 4,573
  • 12
  • 28
  • ok thanks for this suggestion, I will look into it – Red Baron Jun 19 '20 at 12:48
  • This is a good suggestion but I am not sure if it will compress to your requirement every time sometimes after compressing also files are too large. Why don't you add a basic message in the label like specify max upload size and show an error to the user if it exceeds? – Rahul Sahni Jun 19 '20 at 12:54