問題描述
不同語言的 Blob 請求 (Blob request in different language)
我正在嘗試使用私有 API,但我遇到了無法解決的問題。我試圖重新創建的 JavaScript 代碼是
XMLHttpRequest.send(blob);
Blob 的類型為:“image/jpeg”和大小。該 blob 是從 html 輸入創建的。我對 JavaScript 和 Web 開發相對陌生,所以如果不清楚,請原諒。我的問題是如何用任何其他語言(最好是 Java、Python 或 NodeJS)重新創建此請求。據我所知,blob 只是一個大型二進制對象,但我找不到任何信息如何用任何其他語言創建類似 blob 的對象。我希望這個問題有點清楚。
參考解法
方法 1:
In Node.js You could do the following, There is no blob in node.js, you can Buffer instead of blob.
Please check this out.
let imageData = imageFile.toString('base64')
let data = Buffer.from(imageData, 'base64');
var post_options = {
host: '<domain>',
path: '<path>',
method: 'POST',
body: data,
headers: {
'Content‑Type': 'image/jpeg',
'Content‑Length': Buffer.byteLength(data)
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
// handle response
});
(by Jerry、prasana kannan)