Error with uploading image through file transfer

2 posts, 0 answers
  1. Rob
    Rob avatar
    1 posts
    Member since:
    Nov 2014

    Posted 17 Nov 2014 Link to this post

    Hi there -

    I have tried just about every way I can find in the documentation and in these forums to send an image that I have just taken with my device camara. 

    I get my users photo with the following code:, onFail, {
        quality: 100,
        targetWidth : 500,
        destinationType: Camera.DestinationType.FILE_URI,
        sourceType: Camera.PictureSourceType.CAMARA
    function onSuccess(imageData) {
        // hide camara initate button and replace with image from camara
        var image = document.getElementById('otherphoto');
        var other = document.getElementById('nophoto');
        image.src = imageData; = 'block'; = 'none';
        // Set the image from camara to my global image object
        theImage = new Object();
        theImage = imageData;
        // resolve filename and set global filename variable
        window.resolveLocalFileSystemURL(imageData, function(fileEntry){
             fileName =;
        }, function(error){
         console.log('about to resolve this files errors');
    function onFail(message) {
        alert('Failed because: ' + message);

    I then wait for a success callback of a confirmation dialog and trigger the following:

    //set upload options
    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.fileName = fileName.substr(fileName.lastIndexOf('/')+1);;
    options.mimeType = "image/jpeg";
    options.params = {
        text : text
    options.headers = {
        'Authorization': token
    function win(r) {
        console.log("Code = " + r.responseCode.toString() + "\n");
        console.log("Response = " + r.response.toString() + "\n");
        console.log("Sent = " + r.bytesSent.toString() + "\n");
    var fail = function(error) {
        // error.code == FileTransferError.ABORT_ERR
        alert("An error has occurred: Code = " + error.code);
        console.log("upload error source " + error.source);
        console.log("upload error target " +;
    var ft = new FileTransfer();
    ft.upload(theImage, encodeURI(anchorUrl + 'items'), win, fail, options);

    Every time server responds with:  An error has occured: Code = 1.

    I have tried selecting an image from the photo library to see if that makes any difference but it did not. Also to note my file path of my image from camara is "file:///storage/emulated/0/Android/data/me.anchorman.anchor/cache/1416220390031.jpg". Is this correct?

    Any help would be much appreciated.

  2. Tina Stancheva
    Tina Stancheva avatar
    3298 posts

    Posted 20 Nov 2014 Link to this post

    Hi Rob,

    I was not able to reproduce the issue on my side. I attached a sample project I prepared based on the  code snippets you posted. I used a sample Telerik Backend Services project to store the uploaded image and I have no issues uploading it while testing the app on an Android device.

    Can you please run the project on your side and see if it works for you. Let me know how that goes.

    Tina Stancheva

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

Back to Top