0
votes

I am using the following code for uploading picture from android avd.

        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
        options.mimeType="text/plain";
        var filename = imageURI.substr(imageURI.lastIndexOf('/')+1);
        var upload_url="http://example.com";
        alert(upload_url);
        alert(filename);

        var params = new Object();
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;
        options.chunkedMode = false;
        options=null;

        var ft = new FileTransfer();
        ft.upload(imageURI, upload_url, picUploadSuccess, picUploadFailed,options);

but this code adds few extra header info into the file. like following --* Content-Disposition: form-data; name="value1";

test --* Content-Disposition: form-data; name="value2";

param --* Content-Disposition: form-data; name="file"; filename="1.jpg" Content-Type: image/jpeg

therefore when the file stored into the server, it can not be opened as JPEG Image. I have found that the options object is responsible for adding those extra header info. i tried without the options object by assigning null. but still there are few extra info into the file.

Looking forward for suggestions to upload file without any extra info within the file.

2

2 Answers

0
votes

try

options.mimeType="text/jpeg";
0
votes

Well if you take out these lines:

var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;

you won't see:

--* Content-Disposition: form-data; name="value1"; test 
--* Content-Disposition: form-data; name="value2"; param

anymore. However you will still see:

--* Content-Disposition: form-data; name="file"; filename="1.jpg" Content-Type: image/jpeg

as the web server needs to know how to handle the incoming file. I believe the problem to be on the web server end i.e. the script that receives the file.