Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you are trying to upload an image (=file) but in fact you are posting a string returned by <code>img.src</code>. If you like to post your image you'll need to convert it to a string that can be posted. you can do this by loading your image into a canvas element and get call <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement?redirectlocale=en-US&amp;redirectslug=DOM/HTMLCanvasElement" rel="nofollow">toDataUrl</a>. However when using phonegap, I recommend uploading the file through a filetransfer and add your additional post data to it...</p> <pre><code>function uploadPhoto(imageUrlToUpload) { //alert('upload: '+imageUriToUpload); var url=encodeURI(youruploadurl); var params = new Object(); params.your_param_name = "something"; //add your additional post parameters here var options = new FileUploadOptions(); options.headers={Connection: "close"}; options.fileKey = "file"; //depends on the api options.fileName = imageUriToUpload.substr(imageUriToUpload.lastIndexOf('/')+1); options.mimeType = "image/jpeg"; options.chunkedMode = false; //this is important to send both data and files options.params = params; var ft = new FileTransfer(); //what to do during the file transfer? lets show some percentage... var status=$('yourselectorhere');//element in the dom that gets updated during the onprogress ft.onprogress = function(progressEvent) { var perc; if (progressEvent.lengthComputable) { perc = Math.ceil(progressEvent.loaded / progressEvent.total * 100); status.html(perc+'%'+ '('+progressEvent.total+')'); }else{alert('not computable');} }; ft.upload(imageUrlToUpload, url, success, fail, options); } function success(r) { alert("Upload success: Code = " + r.responseCode); } function fail(error) { alert("An error has occurred: Code = " + error.code); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload