Backendless JS-SDK Patch for Appcelerator
- Polyfill for Promise
- Backendless namespace in global scope
- Override Backendless.XmlHttpRequest
- Correct File Upload
- put this patch next to JS-SDK file
-|
|-backendless.js
|-backendless-appcelerator.js
- include the patch to your code before using any Backendless API
//index.js file of your app
...
require('.../path-to/backendless-appcelerator')
Backendless.initApp(...)
...
The patch includes polyfill for Promise, so you can feel free to use it your code
The patch adds Backendless namespace in global scope, so be free to use Backendless without additional require
Backendless JS-SDK, just require
the patch at once in the top of your index file and use Backendless namespace in any files
The patch override Backendless.XmlHttpRequest
by Ti.Network.createHTTPClient
.
You don't need add this fix manually anymore.
before:
Backendless.XMLHttpRequest = function () {
return Ti.Network.createHTTPClient();
};
after:
//do nothing
Appcelerator ENV has little differences with Web and Nodejs environments, so the patch fix it.
Examples:
function uploadTextFile() {
var textFile = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, 'my-text-file.txt');
textFile.write('Hello world!');
Backendless.Files.upload(textFile, 'text-files-directory', true)
.then(function (result) {
Ti.API.info('fileURL: ' + result.fileURL);
})
.catch(function (error) {
Ti.API.error(error);
});
}
function uploadImgFileFromPhotoGallery() {
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-directory', true)
.then(function (fileURL) {
Ti.API.info('fileURL: ' + JSON.stringify(fileURL));
})
.catch(function (error) {
Ti.API.error(error);
});
}
});
}
Backendless Documentation: https://backendless.com/products/documentation/
Support Home: slack.backendless.com
Slack Channel: http://support.backendless.com
Blog: http://backendless.com/blog
YouTube Channel: http://youtube.com/backendless
Facebook: http://facebook.com/backendless
Twitter: http://twitter.com/backendless
We would love to hear from you. Please let us know about your experiences using Backendless. You can reach us through the support page at http://support.backendless.com or email: [email protected]
Thank you and endlessly happy coding!
The Backendless Team