Saroj Kumar ojha
Saroj Kumar ojha

Reputation: 485

Upload a photo using UIWebView

Suppose I have a web page (say filebrowse.html) in a remote server, having a browse file button, I want to access this page via a UIWebView and upload photo from my gallery. (The gallery is on the iPhone.)

Is this possible?

Upvotes: 2

Views: 4441

Answers (3)

jianpx
jianpx

Reputation: 3330

may this will help, it shows you how to choose a photo from webview without using <input type="file" /> in <form></form>

Upvotes: 0

Daddy
Daddy

Reputation: 9035

On iOS, there is no way to "browse the filesystem" so you can't use a form in UIWebView to attach photos for upload. The answer is rather convoluted but here goes:

You're going to have to -

  1. UIImagePickerController to get a picture from the photos album.
  2. Determine the POST headers for the submit form
  3. Encode the image as NSData
  4. Write a POST request with NSURLConnection with the NSData object getting inserted in the proper header

I can't really give you the code for all of this because it needs to be broken down into all of those steps.

Upvotes: 1

Scott Corscadden
Scott Corscadden

Reputation: 2860

Hmm - interesting. Have you tried accessing that page in native Safari? Will it let you browse on the phone? If not (and I'm assuming you're building an app here) you can just use a POST to the form in question (use curl and a browser web inspector to figure out parameters you need, etc).

Upvotes: 0

Related Questions