Search code examples
htmliosfile-upload

Mobile safari image upload and their sizes


As many of know, Safari mobile now allows file uploads through camera or image library.

The 'problem' is that when the picture is taken from the camera, it is sent as it is, meaning it is very heavy in memory (I think it's around 2 or 3 mb even on iPhone 4).

This makes the upload really slow and also bandwidth consuming (not good for mobile). Do you know if, with the <file /> html tag, there is a way to say to iOS: "hey, can you also compress the picture a bit?" - like it's being done when said images are sent via the mail app.


Solution

  • There's a library for that: https://github.com/gokercebeci/canvasResize

    It works by putting the image to a <canvas /> (smaller than original image), then getting the image data so you can post it to your server.