How to send an image as part of multipart/form-data along with other name-value pairs using XMLHttpRequest

297 views
Skip to first unread message

nikhil

unread,
Nov 30, 2010, 3:52:42 PM11/30/10
to phonegap, mhatre...@gmail.com
Hi,

I'm learning Javascript, Html and phonegap at the same time, so spare
my lack of knowledge.

I need to be able to click a picture and send the image along with
some other data to a server.

Find below the code for the analogous functionality in coded for the
browser.

<form id="upload" method="POST" enctype="multipart/form-data" action="/
upload/">
<fieldset>
<legend>Upload a leaf image</legend>
<input type="file" name="myfile" />
<input type="hidden" name="user" value="test" />
<input type="hidden" name="passwd" value="test" />
<input type="hidden" name="fmt" value="json" />
<input type="submit" id="uploadsubmit" name="Upload"
value="Upload" />
</fieldset>
</form>

I need to be able to send all that data to the server. The input type
file will be an image that i take from the camera using the
getPicture() call using phonegap.

I want this event to take place as soon as the user clicks a picture.
I want the POST request to be sent without user intervention. SO i was
thinking to use the XmlHttpRequest object to make this POST request.

Is there any way to send an image alongwith the other data using
XmlHttpRequest?

Really appreciate all the help possible!

Thanks and Regards,
Nikhil

Jesse MacFadyen

unread,
Nov 30, 2010, 5:28:01 PM11/30/10
to nikhil, phonegap, mhatre...@gmail.com
There is currently no way to post files as form data to a server. Either in PhoneGap or Mobile Safari.
The <input type="file"/> tag is not supported.



--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com



--
--
Jesse MacFadyen
{
  blog:'blogs.nitobi.com/jesse',
  email:'jesse.m...@nitobi.com',
  company:
  {
    name:'Nitobi Software',
    site:'www.nitobi.com',
    phone:
    {
      office:'+1 (604) 685-9287',
      tollFree:'1-866-632-2777'
     }
  }
}
Reply all
Reply to author
Forward
0 new messages