[英]Javascript: Temporarily store and display image received from backend as binary data?
[英]store binary data of media(image/video) received from whatsapp cloud API
我必須存儲從 whatsapp 雲 api 收到的二進制數據。 我正在使用節點 js,但無法使用表單數據發送文件數據
這是我提到的參考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);
});
}
在 getMediaData() api 調用中,我們必須將“responseType”定義為“streame”,它將二進制數據作為流格式axios 調用,我們必須傳遞“res.data”而不僅僅是 res。 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.