0

I have to submit form with an image + some additional form fields (mulitipart form submission request). I have tried this

function upload() {
    var img = document.getElementById('image');
    var imageURI = img.value;
    var options = new FileUploadOptions();
    options.fileKey = "photo";
    options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
    var params = new Object();
    options.params = params;
    var ft = new FileTransfer();
    ft.upload(imageURI, "https://www.example.com/upload.php", win, fail,
        options);
}

function win(r) {
    console.log("Code = " + r.responseCode);
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent);
}

function fail(error) {
    alert("An error has occurred: Code = " + error.code);
    console.log("upload error source " + error.source);
    console.log("upload error target " + error.target);
}

html is

<input type="file" id="userImage" name="photo">

but it is returning error code 1 and image path is fakepat\1089001 it is also not getting picture name instead a number is showing? so how do i get image path from input text box?

If i hard code the image (only for testing) in src then request

error code 1 undefined varailbe image

Remember i have to submit image in base64 url

Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186

1 Answers1

1

Additional form data would be sent in your params object. Yours is blank now, but you could do

options.params.formkey1 = value1;
options.params.formkey2 = value2;

As for your second question (and I'd try to keep things limited to one question at a time), you need to pass the path of the file on the device. See the docs for File Transfer.

Finally, you don't need to use base64 to upload the data. I'd avoid that as it is bigger than binary data. Just let FileTransfer push up the binary data. It was built to do so.

Raymond Camden
  • 10,661
  • 3
  • 34
  • 68