Error while uploading image (Cordova-plugin-file-transfer)

Asked

Viewed 560 times

1

I’m using the same code as documentation, but when sending to PHP, no file appears.

JS

function uploadPhotoRevendedor(imageURI) {
    var success = function (r) {
        app.alert("Code = " + r.responseCode + "Response = " + r.response + "Sent = " + r.bytesSent);
    }
    var fail = function (error) {
        app.alert("An error has occurred: Code = " + error.code + "Source = " + error.source + "Target = " + error.target);
    }
    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType = "image/jpeg";

    // Upload image
    var ft = new FileTransfer();
    ft.upload(imageURI, encodeURI(...'model/foto-revendedor.php'), success, fail, options);
}

PHP

print_r(json_encode($_FILES));
$new_image_name = urldecode($_FILES["file"]["name"]).".jpg";
$result = move_uploaded_file($_FILES["file"]["tmp_name"], "../users/".$new_image_name);

http code returns 200 OK in Success function but $_FILES appears empty...

request

  • Is making a mistake?

  • Then returns as 200 - OK the 'responseCode', but don’t know pq in php $_FILES gets empty...

  • Already gave a console.log(imageURI) ? to see if you’re right?

  • Yes the same as the request photo in Request URL

1 answer

0


After trying several solutions and nothing works, I decided to remove the Cordova plugins and add again, I don’t know exactly why but it finally worked!

cordova plugin remove cordova-plugin-file
cordova plugin remove cordova-plugin-file-transfer

cordova plugin add cordova-plugin-file
cordova plugin add cordova-plugin-file-transfer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.