Note that there are some explanatory texts on larger screens.

plurals
  1. POPhoneGap FileTransfer Upload Not Found
    primarykey
    data
    text
    <p>I'm trying to upload an image taken with the device's camera via the FileTransfer.upload method and I'm consistently being given a <code>FILE_NOT_FOUND_ERR</code>. I'm using Cordova 2.2.0 via PhoneGap Build.</p> <p>I'm taking a picture and saving the URI for it into localStorage (via Backbone):</p> <pre class="lang-coffeescript prettyprint-override"><code>navigator.camera.getPicture( (file_uri) =&gt; params.file_uri = file_uri params.is_image = 1 collection.create params (message) -&gt; U.Alert "Failed: #{message}" options ) </code></pre> <p>Then attempting to upload that image:</p> <pre class="lang-coffeescript prettyprint-override"><code>file_uri = @get('file_uri') transferOpts = new FileUploadOptions transferOpts.fileKey = 'attachment' transferOpts.fileName = file_uri.substr file_uri.lastIndexOf('/') + 1 transferOpts.chunkedMode = false transfer = new FileTransfer transfer.upload(file_uri, @url(), success, error, transferOpts) </code></pre> <p>With this, the FileTransfer's <code>error</code> callback is always thrown with the following:</p> <pre class="lang-json prettyprint-override"><code>{ code: 1, http_status: 411, source: "content://media/external/images/media/8416", target: "https://mywebapp.com/api/endpoint" } </code></pre> <p>Code 1 is PhoneGap's <code>FILE_NOT_FOUND_ERR</code> response code. But I've verified the file exists on the device. Firstly, I can display the <code>file_uri</code> as an image on the screen. Secondly, I can retrieve the contents of the image file via the Weinre debugger like so:</p> <pre class="lang-js prettyprint-override"><code>var reader = new FileReader(); reader.onloadend = function(e) { console.log('Read as data URL'); console.log(e.target.result); }; reader.readAsDataUrl(file_uri); </code></pre> <p>The logged <code>data:image/jpeg;base64</code> response is the correct image.</p> <p>Now, I even tried manually resolving the URI like so, as I've seen in one StackOverflow question:</p> <pre class="lang-coffeescript prettyprint-override"><code>resolveLocalFileSystemURI file_uri, (fileEntry) =&gt; fileEntry.file (fileObj) =&gt; transferOpts = new FileUploadOptions transferOpts.fileKey = 'attachment' transferOpts.fileName = fileObj.name transferOpts.chunkedMode = false transfer = new FileTransfer transfer.upload(fileObj.fullPath, @url(), success, error, transferOpts) </code></pre> <p>In this case <code>fileObj.fullPath</code> resolves to: <code>/mnt/sdcard/Android/data/com.COMPANY.APPNAME/cache/1359412873161.jpg</code></p> <p>And <em>still</em> no luck. At this point I'm sure it's something stupid I'm missing!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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