开发者

Does the android web browser allow uploading photos just taken from camera?

One of the crucial requirements in the application I am writing is that user being able to upload开发者_运维知识库 (input type="file") a photo from within a form.

Does the android web browser support File Uploads? If yes do all versions 1.5+ support it?


You can use this:

<input type="file" name="photo" accept="image/*" capture="camera">

The important thing is

capture="camera"

EDIT: as per lastest spec capture is a boolean attribute


Yes and no. Some people seem to have problems doing so (as outlined in the comments). Although it worked for all my devices, it's entirely possible that a different browser might not at all implement this feature.

The user can however not upload any file on the SD Card, but Audio-, Video- and Image-Files that are on the internal/external storage. The kind of files you can upload depend on the installed applications. If you have a File-Manager installed (or shipped with the OS), you can also use it to upload any file you want (Gallery and Mediaplayer should always be present).

When the upload-button of a <input type="file"> is pressed, browsers seem to send the Intent.ACTION_GET_CONTENT-Intent, so every application listening to this is a possible file-source.


The correct format for Device API HTML input is:

<input type="file" name="photo" accept="image/*;capture=camera"></input>

This is supported by devices with Android 3.0 (for tablets) or Android 4.0 and later (for phones). I have no idea which version of iOS starts to support this.


Yes, since Android 3.0 you are able to use device's camera through Device API. This snippet is taken from there

<form enctype="multipart/form-data" method="post">
  <h2>Regular file upload</h2>
  <input type="file"></input>

  <h2>capture=camera</h2>
  <input type="file" accept="image/*;capture=camera"></input>

  <h2>capture=camcorder</h2>
  <input type="file" accept="video/*;capture=camcorder"></input>

  <h2>capture=microphone</h2>
  <input type="file" accept="audio/*;capture=microphone"></input>
</form>

This source looks interesting when it comes to checking html5 support in mobile devices.


I wanted an easier way to get files off my phone rather than pulling out the SD card and I thought to just have a CGI program receive them on a web server so I had the same question. I wrote a small script that can successfully upload files from remote computers using a web browser. It looks like this:

#!/usr/bin/python
import os
import cgi

def tag(tag, contents=None, attlist=None):
    tagstring= "<"+tag
    if attlist:
        for A in attlist:
            V= attlist[A].replace('"','&quot;')
            attstring= ' '+A+'="'+V+'"'
            tagstring += attstring
    if contents:
        tagstring += ">\n"+contents.rstrip()+"\n</"+tag+">\n"
    else:
        tagstring += "/>\n"
    return tagstring

content_type= 'Content-type: text/html\n\n'
form = cgi.FieldStorage()

if not form:
    acturl= "./up.py"
    ff= tag('input','',{'type':'file','name':'filename'}) + tag('input',''{'type':'submit'})
    f= tag('form',ff, {'action':acturl, 'method':'POST', 'enctype':'multipart/form-data'})            
    H= tag('head', tag('title', "Uploader"))
    B= tag('body', tag('p', f))
    print content_type + tag('html', H + B)
elif form.has_key("filename"):
    item = form["filename"]
    if item.file:
        data = item.file.read()  
        t= os.path.basename(item.filename)
        FILE= open("/home/user/public_html/uploads/"+t,'w')
        FILE.write(data)
        FILE.close
        msg= "Success! " 
    else:
        msg= "Fail. "

    H= tag('head', tag('title', "Uploader"))
    B= tag('body', tag('p', msg + tag('a','Another?',{'href':'./up.py'})))
    print content_type + tag('html', H + B)

Running a test with a program like this is the only sure way to know if your brand of phone browser does what you want, but for me: it worked. I was even able to use Apache mod_auth to require a username and password and the Android browser politely let me input that. Then when I selected the choose file button, it brought up a menu offering to let me choose from the Gallery, music ap, sound recorder, and a file manager ap I installed. I picked a file from the gallery and, although it took its sweet time, it uploaded fine. So the answer to the question for me was "yes". And for you - try out a test program like the one posted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜