1

I am using Appgyver to try and upload an image to my custom rest server using the built in Cordova FileTransfer plugin.

(ON ANDROID) Pretty much this is all of my code for trying to upload an image to a REST API. I can get the image and display it AND worse, it actually succeeds and fires the callback (and tells me how many bytes are being sent correctly), but for some reason the server is not getting any parameters with the file. It is currently returning an empty array/object as the list of parameters it's receiving.

(ON IOS) Nothing happens as far as callbacks and I have no idea if the server is receiving anything.

I am using Laravel 4.2 with the Dingo API, Intervention Image, and JWT-Auth plugins.

Server code

$scope.addPost = function(title, price, description, id, uri) 
{

    var fileURL = uri;
    //$scope.encoded = toInternalURL(uri);

    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
    options.httpMethod = "POST";
    //options.mimeType = "image/png";
    options.chunkedMode = false;
    //options.trustAllHosts = true;

    var myToken = JSON.parse(localStorage.getItem("token"));

    var headers = 
    {
            'Authorization': 'Bearer ' + myToken + '',
      'Content-Type': 'multipart/form-data'
  };

    options.headers = headers;

    var params = 
    {
      item_title: title,
      item_price: price,
      item_description: description,
      category_id: id
  };

    options.params = serialize(params);


    var ft = new FileTransfer();
                // name of api is redacted
    ft.upload(fileURL, encodeURI("name of api"), $scope.success, $scope.fail, options);

  };

  $scope.success = function (r) 
 {
    supersonic.logger.log("Code = " + r.responseCode);
    supersonic.logger.log(r.response);
    //$scope.encoded = r.response;
    supersonic.logger.log("Sent = " + r.bytesSent);
    $scope.encoded = "SUCCEED";
};

$scope.fail = function (error) 
{
        $scope.encoded = error.body.toString();
    //supersonic.logger.log(error.body.toString());
    $scope.encoded = "FAIL";
};

Server Code

public function store() {
    return Input::all();
}

The function is so simple because when I use the intervention syntax Image::make('file')..... there is no input called file, and therefore just returns nothing.

Any help would be greatly appreciated.

comu
  • 921
  • 1
  • 11
  • 29

0 Answers0