1

I have an img and I need send this to a post request

My img is document.getElementById('fotoTirada').src=AppMobi.camera.getPictureURL(evt.filename);;

and here the infos from the request

url : http://api.ocrapiservice.com/1.0/rest/ocr
method : POST
request parameters :
image : jpeg
language: string
key: string

how can I do this request?

Musa
  • 96,336
  • 17
  • 118
  • 137
shadsauhduisad
  • 141
  • 1
  • 4
  • 11

2 Answers2

1

Well, you could do this:

  1. Draw in a canvas the image and convert it to base64. See: How to convert image into base64 string using javascript.

  2. Set the base64 in a hidden input value: document.getElementById("input-id").setAttribute('value', base64Img);

  3. Send it using a form, or jquery, or just plain javacsript. In the form method the user will have to push the submit button. Or you could use document.getElementById("form-id").submit();

This is the form:

<form method="post" action="upload.do" id="form-id">
  <input type="hidden" name="base64" id="input-id"/>
  <input type="submit"/>
</form>

Now your upload.do method will have to convert the image back from base64.

Community
  • 1
  • 1
lmiguelmh
  • 3,074
  • 1
  • 37
  • 53
0

You cannot upload a file from a webpage with this approach. If its possible, you could just starting getting user files as they enter your webpage.

The src parameter is just the url to the image, not the data of it.

As I imagine, the image is on client local drive, you can use a <input type="file"> and try to fill it with Java Script, although I think its not possible to change it this way, as this imposes a security risk too, but you can try.

Diego C Nascimento
  • 2,801
  • 1
  • 17
  • 23