Base64 image upload and object save

  1. I am trying to upload an image in base64 format and then assign the upload file to the user object using the below code.
 var byteArray = new Blob(["data:image/jpg;base64," + $scope.imageData]);
 var savedFile = Backendless.Files.saveFile("media", "blouse.png", byteArray, true, new Backendless.Async(uploadOK, uploadError));


 console.log("file : " + savedFile);


 var blouseObject = new Blouse();


 blouseObject.notes = comments;
 blouseObject.user = Backendless.UserService.getCurrentUser();
 blouseObject.approved = 0,
 blouseObject.picture = savedFile;


 var savedObj = Backendless.Persistence.of(Blouse).save(blouseObject);

Are there better way to do this? Are there any size restriction for image file size? I get the below error message making me assume that max file is 2.8 MB.

File Content size must be less than 2,800,000 bytes
  1. Even for a small size file, the uploaded file does not seem to be a valid image file. Am I using the base64 upload process correctly?
  2. I get the below error on creating the object attached with the image file. (image filename is “undefined” even thought it got uploaded successfully).
Cannot save entity with primitive collection property _private_dates
  1. How to automatically assign new file name as in Parse?
    Please share some link or code snipped to be used with JavaScript.
  1. The approach is fine, but why do you need to base64 encode it? If it is a PNG file, just send the bytes of the image without any additional encoding.

  2. See my comment for (1)

  3. Did you use code generator to get the JS code? We have seen this problem before and it was fixed in the 3.0.8 release (released a few weeks ago)

  4. Right now you cannot do that, we’re working on it.

Mark

  1. The image is from the camera plugin using Cordova . To make it work across all android versions, the safest way is to use base64 instead of file url/url.

I have been using the same logic with Parse file upload and it was fine.

  1. Does backendless have file size restriction for upload?

  2. Yes, I am using the code which was generated in the last 3 days. So it should be the latest.

  3. Any tips or workaround for this temporarily?

  1. The rule of thumb with our file upload is: whatever bytes you upload is what you well get back with the download.

  2. Yes, it is about 2mb

  3. I asked someone to investigate the problem

  4. What you’re doing is what we have been recommending - upload a file, put file URL into the object

Do you have ‘cleanPrivateRelations’ function in your generated code?

Yes, I deleted all functions in the class and it works now. Now I have only the class variables.