File Upload Does Not Work with Appcelerator

Hi,
I am using the following code snippet to upload a file to Backendless:


try {
      var fileURL = Backendless.Files.uploadSync( imageFile , 'images', true );
      alert(fileURL);
} catch( error ) {
      alert('Login error: ' + error.message + ' error code: ' + error.statusCode);
}


And I am getting an exception. Thinking that this was an Appcelerator issue, I tried to get assistance from them but they are pointing at Backendless as being the problem:
https://stackoverflow.com/questions/46857340/titanium-64-bit-support-for-stream-specs
Apparently, the Backendless upload code is meant for websites and not mobile OS.

Hi Kam,

Is the “stream” node module included in the package of your app?

Regards,
Mark

Hi Kam

We’ve added some fixes to UMD build, the latest version is 4.1.3.

Could you upgrade backendless.js lib to latest and try out if everything works fine

And also, I see that you are using “sync” method, it’s not good practice and in near future we will remove all the synchronous methods. You can use Promise http://www.appcelerator.com/blog/2017/06/using-javascript-promises-in-titanium/

Regards, Vlad

Hi Vlad,

I used the new backendless.js 4.1.3 and am getting the following exception:

 
 
 
 
 
 
ERROR] : Script Error {
 
[ERROR] : column = 63247; 
 
[ERROR] : line = 1; 
 
[ERROR] : message = "undefined is not a function (evaluating 'Object.setPrototypeOf')"; 
 
[ERROR] : sourceURL = "file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js"; 
 
[ERROR] : stack = "file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:63247\nt@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:61737\nt@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:22243\nt@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:11301\nt@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:60908\nt@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:9409\nt@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:20323\nt@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:59481\nt@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:57477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:59223\nt@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:477\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:834\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:843\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:210\nfile:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:1:332\nglobal code@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/libs/backendless.js:2:70\nrequire@[native code]\nsuccess@file:///var/containers/Bundle/Application/E111F5B0-A270-484F-9FD6-2D0DF5C21934/TrafficTix.app/ui/common/Messaging.js:1:1956"; 
 
[ERROR] : } 
 
[ERROR] : Script Error Module "libs/backendless.js" failed to leave a valid exports object 
 
[ERROR] : ErrorController is up. ABORTING showing of modal controller


this problem is fixed and new version 4.1.4 is released

let us know if you still have any problems with JS-SDK

Regards, Vlad

Hi Vald,

I try to run with the 4.1.4 but getting an error message returned from Backendless. Please see attached.

Thanks,
Kam

IMG_6546.PNG

Could you please create a simple project, only with one button “upload file” for reproduce the problem, it really help up to resolve the problem
zip and send it to support@backendless.com with link on this topic

Regards, Vlad

Hi Kam

I’ve received your email with the simple project and I’m working on it, I’ll let you you know about progress soon

Regards, Vlad

Hi Kam

We’ve created a patch for correct work JS-SDK with Titanium-SDK.
https://github.com/Backendless/backendless-appcelerator/blob/master/lib/backendless-appcelerator.js

Could you please check this out, and confirm if everything works for you.

This patch does not include fix for “sync” file upload method, all “sync” methods will be removed in the nearest future.

I tested it for text file and also for image files from Titanium.Media.openPhotoGallery and all work.
I had iOS device for tests.

 



function uploadTextFile() {
 var textFile = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, 'my-text-file.txt');
 textFile.write('The file is no longer empty!');
 



 Backendless.Files.upload(textFile, 'text-files', true)
 .then(function (result) {
 Ti.API.info('fileURL: ' + result.fileURL);
 })
 .catch(function (error) {
 Ti.API.error('File Upload error: ' + error.message);
 Ti.API.error(error.stack);
 });
}
 



function uploadImgFile() {
 Titanium.Media.openPhotoGallery({
 success: function (event) {
 var imageFile = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, 'my-image-file.png');
 



 imageFile.write(event.media.imageAsResized(100, 100));
 



 Backendless.Files.upload(imageFile, 'img-files', true)
 .then(function (fileURL) {
 Ti.API.info('fileURL: ' + JSON.stringify(fileURL));
 })
 .catch(function (error) {
 Ti.API.error('File Upload error: ' + error.message);
 Ti.API.error(error.stack);
 });
 }
 });
}

Regards, Vlad