Image getting corrupted on Upload to the file storage


Not sure is its a DSP issue, but seeking help in case someone has come across the same issue.

I am using Camera Plugin of Phonegap to take a picture and upload the same using Dreamfactory Angular JS API.

I have already tried the strategies mentioned below:-

  1. Local Storage
  2. File URL
  4. Encode URI as well

Nothing works in getting the data correctly to the server.
The image is correct on the Phone, as I can see the image correctly, on setting it to an image source, before uploading.

My code is below:-
$scope.uploadImage = function(){, onFail,
{ quality: 100,
//destinationType: Camera.DestinationType.FILE_URI,
destinationType: Camera.DestinationType.DATA_URL,
targetWidth: 200,
targetHeight: 200
function onSuccess(imageData) {
$scope.img = {};
$scope.img.src = “data:image/jpeg;base64,”+imageData;
window.localStorage.setItem(“ImageClicked”, “data:image/jpeg;base64,”+imageData);
//$scope.img.src = imageData;

function onFail(message) {
alert('Failed because: ’ + message);

.factory(‘FileService’, function(DreamFactory){
return {
console.log(“entered here”);
var request={};
request.container = “containerName”;
request.file_path = “/image8.jpeg”;
return DreamFactory.api.files.createFile(request);

How to use Angular JS API create file?

Did You try to fetch image from server after upload? Compare differences between retrieved and sent data.
May You test it with some static URI image (not generated from Your camera) like 10px x 10px and post the results here? Just to know more about nature of this corruption.


I tried with the option sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
of cordova camera plugin.

But it also has the same fate.
Shows up fine on the local image src, but the file after upload can’t be opened.


@benbusse , @toddappleton, @jeffreystables

I am unable to get a file uploaded without it being corrupted to the File storage using the Angular JS File API.

Pleas tell me how to get this uploaded?
Below is the code for the same.

I am uploading this from the camera plugin from a mobile, but even if I directly go and upload from your API_DOCs its failing, which signals me that I am doing something wrong.

It is a small png file, which I am assigning to a body variable and then calling the following:-
var request={};
request.container = “container_name”;
request.file_path = “/image23.png”;

This without fail corrupts the file. It gets uploaded though.
Can you please correct the mistake I am making.

var body="âPNG

Here above, I had actually pasted the whole content of a small png file, but it vanished, may be due to some invalid characters.


@praveen Can you please post the original uploaded data as well as the full request and response sent to and returned from your DSP? If you are unable to format it for the forum, please post it somewhere such as Pastebin.

And was @tborja’s code example not useful for you?


I just opened a small png file in a text edit, and have pasted the characters inside that:-

However, I dont know if simply assigning the body to the content like this is the way.

Yes, I have tried the @tborja example as well, and also pasted there. But, I am not sure why getting corrupted.


Can you please verify at your end that the Angular SDK based fileservice works fine for images, and does not corrupt them.
As I see the same behavior with the API Docs as well.

You can explain me the process with a small word doc as well. Basic process would do.
I can see it has a body parameter, but do I just pour in the content of the file or how else its to be done?

I tried Cordova’s File Transfer Plugin, but it uploads a zero size file.
Below imageURI is the fileURI I get from Camera Plugin or Phone Gap.

and this is what I do there:-
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
// options.fileName=imageURI.substr(imageURI.lastIndexOf(’/’)+1);
var params = new Object();
params.value1 = “test”;
params.value2 = “param”;

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

        var ft = new FileTransfer();
        ft.upload(imageURI, "http://URL/rest/file/container//hello123.jpeg?app_name=hospi", win, fail, options);


“Uploaded photo image to DreamFactory folder is corrupted” seems a common problem for many mobile developers. We have encountered this problem as well. Still struggle to find out a solution.
Upload photo is a common feature for many MBaaS but it is difficult to do in DreamFactory backend.

It will be good for DreamFactory developers if some one (e.g. DreamFactory) can share a workable code sample code (e.g. in AngularJS) for the photo image upload function.




Here is a link provided previously to users having trouble uploading and retrieving base64-encoded images. Be sure that you are encoding and decoding properly.


Same problem when uploading images as multipart file in android. Tested using Ion library and AsyncHttpClient (loopj).