Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to use the <a href="http://docs.phonegap.com/en/3.2.0/cordova_file_file.md.html#FileTransfer" rel="nofollow"><code>FileTransfer</code></a> API, note that there are some problems with it at the time of writing (<a href="https://issues.apache.org/jira/browse/CB-2293" rel="nofollow">however they are being addressed.</a>).</p> <p>See the documentation here for details. <a href="http://docs.phonegap.com/en/3.2.0/cordova_file_file.md.html#FileTransfer" rel="nofollow">http://docs.phonegap.com/en/3.2.0/cordova_file_file.md.html#FileTransfer</a></p> <p>Here's a quick example:</p> <pre><code>var fileURI = // imageURI returned by the CameraAPI. var success = function (r) { console.log("Code = " + r.responseCode); console.log("Response = " + r.response); console.log("Sent = " + r.bytesSent); } var fail = function (error) { alert("An error has occurred: Code = " + error.code); console.log("upload error source " + error.source); console.log("upload error target " + error.target); } var options = new FileUploadOptions(); options.fileKey = "file"; options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1); options.mimeType = "text/plain"; // The following options are to attempt circumvention of the // FileTransfer.upload issues in the linked Cordova thread. // Note that they are reportedly, not always effective. options.headers={Connection: "close"}; options.chunkedMode = false; var params = {}; params.value1 = "test"; params.value2 = "param"; options.params = params; var ft = new FileTransfer(); ft.upload(fileURI, encodeURI("http://some.server.com/upload.php"), success, fail, options); </code></pre> <p>You will need to enable the file and file-transfer plugins in your Android Manifest.</p> <pre><code>&lt;gap:plugin name="org.apache.cordova.file" /&gt; &lt;gap:plugin name="org.apache.cordova.file-transfer" /&gt; </code></pre> <p><strong>A quick note about the known problems...</strong> uploading will fail on every other subsequent upload (ie. success, fail, success, fail, etc...) - Note that this problem has affected iOS and Android (I can't speak for BB or other platforms.) AFAIK, Android is still affected, but I recommend you <a href="https://issues.apache.org/jira/browse/CB-2293" rel="nofollow">read the thread</a> and keep an eye on it.</p> <p>There are recommended solutions/workarounds, however they are also reported to fail (ie. turn off chunked mode and attempting to force close the connection.) </p> <p>Until there is a reliable fix, it is better to simply keep an attempted connection counter, and handle the even numbered fails as cause to immediately re-try. (nasty, but necessary.)</p>
 

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