Server Code Blob Error

So I am using Server Code to store sensitive data in files in a specific administration folder on the Backendless server. I use the Blob type to create the file content to save. But whenever the server executes:

const otherEmails = new Blob([JSON.stringify(otherEmailList)], {
type: “application/json”
});

(Assume otherEmailList is a valid Javascript Object)
I seem to get this error:

VM20266:1 POST https://api.backendless.com/APPKEY/RESTKEY/services/MyService/sendAdminMail 400 (Bad Request)
mail.js:358 Message Error Error: Request failed with status code 400
at createError (createError.js:17)
at settle (settle.js:19)
at XMLHttpRequest.handleLoad (xhr.js:78)

Hi Shaiv

I believe the issue is with Blob, cloud code is running on NodeJS env, since Blob is working in Browser https://developer.mozilla.org/en-US/docs/Web/API/Blob
So, could you please check what error message you get in response body, there should be something like this: “Blob is not defined”

For saving files from cloud code you do not need to create a new Blob, just pass the file content as it is.

 testMethod() {
    const data = [{foo:123}, {bar:'str'}]
    const json = JSON.stringify(data);

     return Backendless.Files.saveFile( 'test-ser', 'my-file.json', json, true )
  }
1 Like

Yep, that solves my problem, thanks :slight_smile: