Kamron Clark avatar image
Kamron Clark asked Kamron Clark commented

Attach audio data to create custom user greeting endpoint

Part of my application retrieves base64 encoded audio data from another API, stores that data as a variable in a data buffer, and then uses that data as the "binary" parameter for the create custom user greeting endpoint. This worked perfectly in Nodejs, I was able to convert the base64 encoded audio data into a stream and pass that into the node form-data like so:

const NodeFormData = require('form-data');
formData = new NodeFormData();

let body = {
    type: "Introductory",
    answeringRule: {id: "38"}

formData.append('json', new Buffer.from(JSON.stringify(body)), {
      filename: 'request.json',
      contentType: 'application/json'

formData.append('binary', audioStream, {
    filename: 'audioStream.mp3',
    contentType: 'audio/mpeg'

However, when refactoring the application for native browser JavaScript, I get the error:

"Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'."

It appears that the native JavaScript FormData must have a Blob object if you are attaching a file. However, when I change the format of the audio data from stream to Blob, I get this error message on the RingCentral end:

"Invalid Attachment Media Type"

It is important to note that the audio data in my application is never saved into a file, only stored in a variable, so I cannot simply attach a file. How can I get this process to work in native JavaScript?

rest apicustom greeting
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Phong Vu avatar image
Phong Vu answered Kamron Clark commented

Try this to see if it helps.

1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Kamron Clark avatar image Kamron Clark commented ·

I still can't get this to work. Native JavaScript FormData.append() requires a Blob or File object to append audio data to the FormData. However, no matter how I construct this object, I always get

ERROR: 400 (Bad Request)

With the error detail

Uncaught (in promise) Error: Unsupported attachment media type

Here is my most recent code

let body = {
        type: "Introductory",
        answeringRule: {id: "3036"}
formData.append('json', bodyBlob, {
          filename: 'request.json',
          contentType: 'application/json'

formData.append('type', body.type);
formData.append('answeringRuleId', body.answeringRule.

formData.append('binary', new File([audioBuffer], "audio.mp3", {type: "audio/mp3"}), {
        filename: 'audioStream.mp3',
        contentType: 'audio/mp3'

Is there any way around this problem? To construct the Blob or File object in a way that the API will accept it? or is there a way to bypass the FormData all together?

0 Likes 0 ·

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys