mobile safari image upload & their sizes

2020-07-05 12:56发布

Ok so 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.

Thanks in advance.

2条回答
我想做一个坏孩纸
2楼-- · 2020-07-05 13:13

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.

查看更多
【Aperson】
3楼-- · 2020-07-05 13:15

I don't think you can actually do anything there. What you can do though is use the FILE API and slice the upload in smaller chunks, reducing the memory overload.

Here is an excellent post on how to do this:

http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-slicing-files

查看更多
登录 后发表回答