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
Sending MMS from an image url
Tags: sms and text messaging
Jun 9, 2023 at 11:37pm   •   1 replies  •  0 likes
Zackry Cooper

Using the nodejs package, I'm able to successfully send a MMS message containing an image when I load the image directly from the file system (using fs.createReadStream() like the example in the api docs shows). However, I want to load the image from a url instead. When I try using a Readable stream, the api response is just 400 - Bad Request.

Any ideas what could be wrong?

Here's the code snippet:

const FormData = require('form-data');
let fd = new FormData();

let txt = {
  from: { phoneNumber: this.phone },
  to: [
    { phoneNumber: to }
  ],
  text: msg
}

fd.append('json', new Buffer.from(JSON.stringify(txt)), {
  contentType: 'application/json'
} );

const resp = await axios(url, {method: 'GET', responseType: 'arraybuffer'});

fd.append('attachment', Readable.from(Buffer.from(resp.data, 'binary')), {filename: 'file.png', contentType: resp.headers['content-type']});

const resp = await this.platform.post(endpoint, txt);


I've confirmed the axios download is successful ... not sure what I'm missing with the Readable stream, though.

1 Answer
answered on Jun 12, 2023 at 8:44am  

Why do you need the Readable.from. Just remove it. Also you call the post with the txt part, not the form data!

fd.append('attachment', Buffer.from(resp.data, 'binary'), {filename: 'file.png', contentType: resp.headers['content-type']});

// Fixed 
const resp = await this.platform.post(endpoint, fd);



 0



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