Upload image URI

Hi Raul,

I made a few changes and uploaded a new version to:
http://backendless.com/sdk/js/2.0.2/backendless.js

Here’s a sample that works:

Backendless.UserService.login( userid, pwd );


// this will return user only if there is explicit Backendless.UserService.login 
// call in the current session
var user = Backendless.UserService.getCurrentUser();
console.log( "user " + user );


// this will return objectId of the logged in user
// the value is available when stayLoggedIn is either true or false
var userObjId = Backendless.UserService.loggedInUser();
console.log( "user obj id - " + userObjId );

Cheers,
Mark

Thank you Mark, is working.

Hello guys,

When I was compiling my application(Cordova) for Android the error returned:
Uncaught #<Object>sendEncoded @ backendless.js:2853

and then another one appears:
PUT file:///android_asset/www/undefined net::ERR_FILE_NOT_FOUND sendEncoded @ backendless.js:2845

Raul,

I am not sure what is means to “compile Cordova application for Android”. What would be very helpful for us is if you could describe how to reproduce the problem by using an API from our library.

What does the app do when the error happens? What API does it use? What are the argument values? This would let us pin point the problem and then fix it.

As for the problem with :ERR_FILE_NOT_FOUND", it sounds like it references a file which does not exist.

Regards,
Mark

Apache Cordova is a platform for building native mobile applications using HTML, CSS and JavaScript. I am also using the Angularjs.

I’m using Backendless SDK v2.0.1 for JavaScript. Everything is working, however the Backendless.Files.saveFile() is not working when I compile my project on Android.

var byteArray = new Blob([‘foo bar’]);
var savedFile = Backendless.Files.saveFile( “testfolder”, “fox.txt”, byteArray, true, new Backendless.Async(function(e){
console.log(‘sucesso’, e);
}, function(e){
console.log(‘erro’, e);
}));

Try/Catch and Async not work. You need more details?

This is an issue we fixed 2 days ago and right here you confirmed that this code works:

http://support.backendless.com/t/upload-image-uri#comment-3046

What has changed?

Yes, it works in Firefox, Chrome and Internet Explorer but does not work on my phone.

Do you think it might be a problem with the JS support on the phone? Have you tried debugging it there?

In Files.prototype.saveFile() we have:
var reader = new FileReader();
reader.fileName = fileName;
reader.uploadPath = baseUrl;
reader.onloadend = sendEncoded;
if (async) {
reader.asyncHandler = async;
}

The var asyncHandler = this.asyncHandler within sendEncoded() is returning undefined.
The asyncHandler not exists in FileReader()
(https://developer.mozilla.org/pt-BR/docs/Web/API/FileReader)

Maybe that’s part of the problem, what do you think?

No, that’s not the problem.

asyncHandler does not need to exist there (neither does uploadPath for that matter).

We assign a property and use it later on in sendEncoded. FileReader is still just an object - you can put any property into it.

Regards,
Mark

Yes, but reader.fileName, reader.uploadPath and reader.asyncHandler when called in sendEncoded() they come as ‘undefined’. I did like this and it worked:

I declared

var readerFileName = null;
var readerUploadPath = null;
var readerAsyncHandler = null;

Files.prototype.saveFile()

var reader = new FileReader();
/*reader.fileName = fileName;*/
/*reader.uploadPath = baseUrl;*/
readerFileName = fileName;
readerUploadPath = baseUrl;
reader.onloadend = sendEncoded;
if (async) {
/*reader.asyncHandler = async;*/
readerAsyncHandler = async;
}
reader.onerror = function (evn) {
async.fault(evn);
};
reader.readAsDataURL(fileContent);
if (!async) {
return true;
}

And sendEncoded()

builder = getBuilder(readerFileName, e.target.result, boundary),
..........
xhr.open("PUT", readerUploadPath, true);
..........
var asyncHandler = readerAsyncHandler
..........

Mark,

You will make some modification in the FileReader?

Raul,

I apologize I could not respond sooner.

I am hesitating to make these changes - declaring global variables just to pass the data into an asynchronous callback is a bad practice.

I’d like to be able to reproduce the error on our side. I tried all browsers on desktop (Chrome, Safari, Firefox) and it works everywhere. You mentioned it breaks in a mobile deployment. Could you please let me know the steps to reproduce the issue? If you could provide an example we could just run, it would go a long way.

Regards,
Mark

Hi guys , I have the same problem with Backendless.Files.upload(files, directory, override, async) using inside Ionic platform… on browser it work fine but on device I have problem here: “xhr.open(“POST”, this.uploadPath, true);” this.uploadPath return undefined inside send function in backendless.js

Sorry for my bad english and thanks a lot for your support.

Regards, Valerio

Hi Valerio,

Have you tried stepping into the code (including our code) to see where the error occurs? We made our libraries open source and value community involvement greatly!

Cheers,
Mark

Hi Mark,
thanks for answer… I just already mentioned that error occurs in your code in backendless.js when this.uploadPath return undefined but I don’t know how to correct it! Have you any suggestions?

Hi Valerio,

If you provide some example code which reproduces the described behaviour, it would help much.
In what cases does the uploadPath appear to be undefined?

Need to upload base64 also.
File uploaded broken to backendless server

Can i get a link of example ?

Hello @tomer_moas, could you create a separate topic with the following pattern:

Steps to reproduce:

1. ..
2. ..
....

Actual result
...

Expected result
...