store binary data of media(image/video) received from whatsapp cloud API

Viewed 30

i have to store binary data of which i received from whatsapp cloud api. i am using node js but unable to send the file data using form data

here is reference i have referred https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#example-2

function handleMedia(id, number) {
  mediaServiceApi(id).then((res) => {
    console.log(res.data.url);
    console.log(res.data.mime_type);
    getMediaData(res.data.url).then((res) => {
      var datafm = new FormData();
      datafm.append("mobile_number", `${number}`);
      datafm.append("category", "1");
      datafm.append("ticket_type", "1");
      datafm.append("subject", "Device not working");
      datafm.append("description", "my device is not working");
      datafm.append("document", res);

      var config = {
        method: "post",
        url: "",
        headers: {
          "Access-Token": "",
          "Content-Type": "multipart/form-data",
          ...datafm.getHeaders(),
        },
        data: datafm,
      };

      axios(config)
        .then(function (response) {
          console.log(
            "this is JSON data of ticket created",
            JSON.stringify(response.data)
          );
        })
        .catch(function (error) {
          console.log(error);
        });
    });
    let textmsg = `We have registered your query with refrance of a media`;
    textServiceApi(textmsg, number);
  });
}
1 Answers

in the getMediaData() api call we have to define "responseType" as a "streame" which will get the binary data as a streme format axios call and we have to pass "res.data" instead of just res. thanks

Related