image – Prevent auto-saving of photos to gallery when uploading photos in Android Browser using input type=file capture=camera-ThrowExceptions

Exception or error:

I am using a well-known HTML 5 method of capturing and uploading images that will support most recent smartphones. Here’s my code:

<input id="attach-file" type="file" accept="image/*" capture="camera">

Works beautifully on all the devices I care about.

Problem is this:

On Android, the file you capture auto-saves to the gallery. I am implementing this in an application where privacy and security are very crucial. We cannot have the file saving to the users’ device. Does anyone know a way of preventing the OS from autosaving the pictures?

How to solve:

There’s not way to prevent saving.

In web applications, the client-side is sandboxed and for security reasons you cannot control anything outside the scope of your website.

However, you can try this solution (it won’t work on all devices):

  • Instead of using a <input> tag, you can implement the camera capture by yourself by using getUserMedia and a <canvas>.
  • Use the <input> method only as a fallback (in case the end-user device doesn’t support getUserMedia).

This method will require users to allow the access to the camera, but it won’t be saved on user’s device because captures are saved into memory.
Also, if you need to save the result to your servers, you’ll have to convert the canvas to a data URI and then convert the data URI to a blob and upload the blob through AJAX with multipart/form-data.

I’d recommend to Google “html5 camera getusermedia” for more information.

Leave a Reply

Your email address will not be published. Required fields are marked *