Getting error "Backendless.XMLHttpRequest is not a constructor" when running Business Logic

I have no idea what the problem is.
My code:


/*Created on 08/22/2017 11:59:34.*/


class MyService {
 /**
 * @param {String} name
 */
 
 helloWorld(name) {
 return new Promise((resolve, reject) => {
 
 
 var queryBuilder = Backendless.DataQueryBuilder.create();
 getIngredients( queryBuilder );
 
 
 
 
 function getIngredients( queryBuilder ) {
 Backendless.Persistence.of("Ingredients").find( queryBuilder )
 .then( handleResult )
 .catch( handleError );
 }
 
 function handleResult( ingredients ) {
 printIngredients( ingredients );
 
 if( ingredients.length > 0 ) {
 queryBuilder.prepareNextPage();
 getIngredients( queryBuilder );
 }
 else {
 console.log( "Reached the end of collection" );
 } 
 }
 
 function handleError( error ) {
 console.log( "Server reported an error - " );
 console.log( error.message );
 console.log( error.errorCode ); 
 return "E-"+error.message;


 
 }
 
 function printIngredients( ingredientsCollection ) {var ingredients = [];
 var ing = "";
 
 for( var i in ingredientsCollection )
 ing = ing + ingredientsCollection[ i ].namePrint + ","; 
 
 
 
 var data = [];
 for (var i = 0; i < ing.length; i++){ 
 data.push(ing.charCodeAt(i));
 }
 
 var savedFile = Backendless.Files.saveFile( "testfolder", "test.txt", data, true)
 .then( function( fileURL ) {
 resolve(fileURL);
 })
 .catch( function( error ) {
 reject(error.message);
 }); 


 }
 
 });
 }
}
Backendless.ServerCode.addService( MyService );

Hi Sean,

Does the same service call work when you run the service in the debug mode?

Regards.
Mark

No i get the same error

Hi, Sean,
I’ve reproduced this error. I’m sure the problem is in the method saveFile, not in your code.
I’ve created the internal ticket (BKNDLSS-15887). We will let you know as soon as it is fixed.

Regards Ilya

Hi Sean

As workaround I can propose you this one:


const directoryPath = 'my-directory/and-sub-directory'
const fileName = 'my-cool-file.txt'
const data = ['hello', 'there']
const content = JSON.stringify(data)


return Backendless.Request
  .put(`${Backendless.appPath}/files/binary/${directoryPath}/${fileName}?overwrite=true`)
  .set({ 'Content-Type': 'text/plain' })
  .send(Buffer.from(content).toString('base64'))

http://support.backendless.com/public/attachments/1c76bf3dba4e58d045ba749f260acf6a.png&lt;/img&gt;

Regards, Vlad

We have fixed it in the new 4.1.0 version of JS-SDK