Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

File upload working but unreadable

Hi. I'm trying to upload a photo taken by the camera to sharefile. I've been digging through all the documents etc i can find including this thread: https://getsatisfaction.com/apperyio/...
and as a result I'm able to upload a file. The problem is the file is unusable. When I try to open it with windows photo viewer it says its damaged corrupted or too large..
The javascript I'm using is and you can see based on the one in the link above (UploadfromCamera):
function FileUpload() {

var serverUrl = localStorage.getItem('locURL') + '&filename=' + encodeURIComponent(getFileName());
var imageDataBase64 = localStorage.getItem('locImage');
var rawdata = Base64.decode(imageDataBase64);

alert(serverUrl);

$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("Content-Type", "image/jpeg");
},

url: serverUrl,
data: rawdata,
processData: false,
contentType: false,
success: function(data) {

alert("Upload successful");
},
error: function(data) {
// do something in case of an error...
alert(data.responseText);
}
});
}

Any ideas will be greatly appreciated.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

File upload working but unreadable

Hi Bob,

Please take a look at here: http://docs.phonegap.com/en/2.4.0/cor...

Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

File upload working but unreadable

Yes. Thought about that. It means I need to change the camera settings to output a fileuri and use that as input for the transfer rather than the raw image doesn't it?

Bob Fludder
Posts: 0
Joined: Fri Sep 14, 2012 1:09 am

File upload working but unreadable

Right. Have tried this but am getting a similar result. I can see some "additional" data inside the image: --+++++
Content-Disposition: form-data; name="file"; filename="image.jpg"
Content-Type: image/jpeg
I know this is outside your support but any ideas would be great.
Thanks

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

File upload working but unreadable

Bob,

You correctly reconfigured Camera service to return the name of received file. Now you would need to read it from the device file system to buffer and pass it on to our backend as usual file upload, NOT to the collection, namely the file. It was already discussed here in the forum.

Return to “Issues”