Upload image URI

Hello,

It is possible to send a string with the URI of the image rather than sending FileList object? (without the input type file)

Hi Raul,

Do you mean adding some additional data along with a file upload?

Regards,
Mark

No,
I am talking about Data URI, for example:

var imageDataURI = “data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7”;

I want to upload that image (imageDataURI), this is possible?

I also think that this page is outdated:
http://backendless.com/documentation/files/js/file_save_files_from_byte_arrays.htm
Backendless.FileService.saveFile()

1 Like

The page is not outdated, it reflects what the current API supports. Which part do you believe is out of date?

The contents of the file cannot contain the content type, it must contain just the contents of the file.

Regards,
Mark

My console returns: “Error: Backendless.FileService is undefined”

Go to the line 2887 of backendless.js file (“saveFile: function (path, fileName, fileContent, overwrite, async)”)

The correct should be: Backendless.Files.saveFile ()

Am I right?

Yes, you are right. It will be fixed shortly.

This has been corrected. Thank you for bringing it up to our attention.

Mark,

My console return: Uncaught #<Object> sendEncoded @ backendless.js:2853

var byteArray = new Blob( [“01100110”, “01101111”, “01101111”] );
var savedFile = Backendless.Files.saveFile( “testfolder”, “fox.txt”, byteArray, true);
console.log( savedFile );

I’m doing something wrong?

I think you’re initializing your Blob incorrectly. Try this:

https://jsfiddle.net/pfa2c29n/

Make sure to put your app id and secret key. Once you run it, open Backendless console and navigate to Files > \testfolder. There should be fox.txt in there.

Regards,
Mark

He keeps giving error. It saves the file only in Google Chrome (with error).

It saves the file on the server when you use Google Chrome? Can you attach a screenshot showing the error?

Yes, only in Chrome. In Firefox and Cordova compiled for Android have not worked.

What does the server respond with?

message: “Corrupted text/plain request. File contents has wrong request body”
code: 6017

Thanks. We will investigate this further.

Thank you Mark.

Hello, Raul!

The issue has been fixed.
Can you please check again and confirm?

with best regards,
Alex Navara

It works in firefox. But now I can not log me in my project, yesterday was working. You changed something in Login?

You cannot login to Backendless console or your application? Please provide steps to reproduce the problem.

var user = Backendless.Data.of(Backendless.User).findById(Backendless.UserService.loggedInUser());

Backendless.UserService.loggedInUser() is not returning the current-user-id, then the findById is giving error.

var user;
try{
user = Backendless.UserService.login( ‘my@mail.com’, ‘123’, true );
console.log(user); /* returns true */
}catch( err ) { }

console.log(‘Backendless.LocalCache’, Backendless.LocalCache.getAll());
/* returns: “Backendless.LocalCache” Object { stayLoggedIn: true, user-token: “9A1DC65D-426D-F88D-FF8E-8DE8B7EC3000” }
*/