0

I'm using npm module

https://www.npmjs.com/package/@twilio/conversations

I'm sending media with below code:

props.conversationProxy.sendMessage({
  contentType: event.target.files.files[0].type,
  filename:event.target.files.files[0].name,
  media: event.target.files.files[0]
});

I have tried below for file names, but nothing works

file_name:event.target.files.files[0].name,

fileName:event.target.files.files[0].name,

FileName:event.target.files.files[0].name, 

file:event.target.files.files[0].name, 

name:event.target.files.files[0].name

getting below from twilio:

{ 
contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
​​
filename: null
​​
sid: "MEXXXXXXXXXXXXXXXXXXXXXXXXXX"
​​
size: 4697
}

I want to send media with filename.

Prashant Patil
  • 2,463
  • 1
  • 15
  • 33

2 Answers2

1

Twilio developer evangelist here.

The SDK docs show that the options you can pass when sending media through the Conversations SDK (the Conversation#SendMediaOptions) are:

Name        | Type          | Description
------------|---------------|----------------------
contentType | String        | content type of media
media       | String/Buffer | content to post

filename is not an option, so you cannot pass it to the SDK.

According to the documentation, you can set the filename by providing the data as a FormData object:

const formData = new FormData();
formData.append('file', event.target.files[0]);
formData.append('filename', event.target.files[0].filename);
formData.append('contentType', event.target.files[0].type);

channel.sendMessage(formData);

I haven't tested this, but hopefully it works.

philnash
  • 70,667
  • 10
  • 60
  • 88
0

The correct way to get file name is

event.target.files[0].filename
SaGaR
  • 534
  • 4
  • 11