twilio / twilio-chat-demo-js

Programmable Chat API Demo Application for JavaScript
BSD 3-Clause "New" or "Revised" License
90 stars 94 forks source link

Can't post media to channel #37

Closed AshrafHefny closed 2 years ago

AshrafHefny commented 6 years ago

I am trying to post media using sendMessage function but it's not working

channel.sendMessage({
      contentType: 'image/svg+xml; charset=utf-8',
      media:
      '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">' +
      '<path d="M50,3l12,36h38l-30,22l11,36l-31-21l-31,21l11-36l-30-22h38z"' +
      ' fill="#FF0" stroke="#FC0" stroke-width="2"/></svg>',
  }).catch(function (reason) {
    console.log(reason);
  });

This coe reutrns no errors, but I can't send the image?!

aleksandrsivanovs commented 6 years ago

so, there is no error (i.e. catch block is not executing) or there is empty error?

AshrafHefny commented 6 years ago

@aleksandrsivanovs thanks for your response. no there is no errors at all

JigneshPatel04 commented 6 years ago

Hello I am sending file with FormData() and it is working in my own demo.

FileUpload(files: FileList) { const formData = new FormData(); formData.append('file', files.item(0)); this.file = files.item(0); // Get active channel sid const channelSid = this.activeChannel.sid; if (channelSid) { this.chatClient.getChannelBySid(channelSid).then( channel => { // send media with all FormData parsed atrtibutes channel.sendMessage(formData).then(msg => { console.log('Media message', msg); this.loading = false; }); }, error => {

    }
  );
}

}

hope, it is working for you. lets me know if any problem on thats.