0

I have the a function that POST a text message alright, but I'm trying to include an image file/attachment with it but no luck:

// this function sends over the message 
createMessage ( messageToSend, callback ) {
  return utils.ajax( {
    url: '/messages',
    type: 'POST',
    data: messageToSend
  }, callback );
}

I include what I need to send like this

const messageToSend = {
     text: this.message,
     attachments: this.attachments
};       

return api.createMessage( messageToSend, ( message ) => {    
   // some code
} );

When passing the object, the text is included but the image file /attachment was never included. What could I have missed?

  • what do you have a server? please tag question. – derloopkat Oct 17 '17 at 16:52
  • 2
    Spitballing a few guesses. maybe try sending as a [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) object, it handles file upload encoding for you. Make sure you are uploading the correct content type. make sure you have the image stored before sending. – D Lowther Oct 17 '17 at 16:56
  • And if you don't want to send FormData you'd have to send the image as a base64 string. – Gratus D. Oct 17 '17 at 16:59

0 Answers0