In my site I use the option to upload photos. In case of uploading from mobile the picture size is very large (2MB+). I wonder if there is a way to give the user an option to determine the size (original, medium, small), so that the storage won’t explode, and more important - sometimes I need to send the pictures via email, so too large pictures are blocked…
@yisrael-wix maybe you have any idea?
Hey there, great question. If you’re receiving the images using the File Upload Button, you can actually validate/block the uploads that are over a certain size, before they happen.
So for example, you could:
-
Check if they’re on mobile
-
Check the File Size once a file has been selected (using the onChange ())
-
Check the size of the file they’ve selected, before you startUpload().
You can do the third step with code like this:
/**
* Adds an event handler that runs when an input element's value
is changed.
* @param {$w.Event} event
*/
export function uploadButton1_change(event) {
console.log(event);
if(wixWindow.formFactor === "Mobile"){
const fileSizeInBytes = event.target.value[0].size;
//You can use the number 2097152 to equal 2 MB.
if(fileSizeInBytes > 2097152){
//This is where you can write code to show a message to them.
}
}
}
Let me know if this helps along the lines of what you’re aiming to achieve.
Thank you Chris, but it’s not exactly what I need. I don’t wand to just block big pictures, I would like to:
A. Give the user options
B. If the user choose “small” to shrink the picture