News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Attach audio data to create custom user greeting endpoint
Tags: rest api, custom greeting
Sep 20, 2022 at 7:21am   •   1 replies  •  0 likes
Kamron Clark

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?

1 Answer
answered on Sep 20, 2022 at 10:16am  

Try this to see if it helps.


 0
on Sep 30, 2022 at 10:00am   •  0 likes

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?



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us