brdeav39
brdeav39

Reputation: 41

Cordova FileTransfer Plugin error code 1 for image upload

I am trying to take a picture on my phonegap app and then use the FileTransfer plugin to upload it to my server. I am getting error code 1 but there is no other explanation - this is VERY frustrating. I have scoured every piece of documentation and blog known to man with no luck.

I am using a basic LAMP server and it continues to give me an http 500 code. I am 99.9% sure this error is specific to my server because I have tested this with a different web server of mine and the code works fine. Here is the response:

{"code":1,"source":"file:///storage/emulated/0/Android/data/io.cordova.xxappxx/cache/1477607161788.jpg","target":"https://server.com/php/uploadPhoto.php","http_status":500,"body":"\t","exception":"https://server.com/php/uploadPhoto.php"}

Below is my front-end js code:

function uploadPhoto(imageURI) {
    var options = new FileUploadOptions();
    options.fileKey="file";
    options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
    alert(options.fileName);
    options.mimeType="image/jpeg";

    var params = {};
    params.value1 = sessionStorage.getItem("token");
    options.params = params;
    options.chunkedMode = false;
    options.headers = {Connection: "close"};

    var ft = new FileTransfer();
    ft.upload(imageURI, "https://servername.com/php/uploadPhoto.php", function(result){
    console.log(JSON.stringify(result));
    }, function(error){
    console.log(JSON.stringify(error));
    }, options, true);
}

And here is my back-end PHP code that is being called (uploadPhoto.php):

<?php
session_start();
header('Access-Control-Allow-Origin : *');
$new_image_name = "$userId.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "/var/img/".$new_image_name);
?>

Upvotes: 1

Views: 1806

Answers (1)

brdeav39
brdeav39

Reputation: 41

This ended up being an issue of image size. I was working on this project for a university and their servers have lots of security installed - one of these security configurations had a very small file upload size limit which was blocking the uploads. I discovered this by scanning some of the log files in the /var/log/ directory.

Upvotes: 1

Related Questions