在node.js HTTPS帖子中发送二进制正文

时间:2019-02-04 14:23:09

标签: node.js

我有以下采用base64字符串的代码,并将其发送给接受二进制的API。我收到来自api调用的空响应

    let base64String = event.base64String;
    // pass the base64 string into buffer
    let buffer = new Buffer(base64String, 'base64');

    // TODO check file type

    processImage(buffer)
        .then(result => {
            console.log("result are " + result);
            callback(result);
        }).catch(error => callback(error));


let processImage = function (buffer) {
    // get the file extension
    return new Promise((resolve, reject) => {

        var options = {
            method: 'POST',
            url: 'https://<UR - not visible for privacy>',
            headers:
            {
                'Content-Type': 'application/octet-stream'
            },
            body: buffer.toString('binary')
        };

        request(options, function (error, response, body) {
            if (error) reject(error);

            console.log(body);

            resolve(body);
        });
}

在邮递员中的等效之处在于,我只是在主体中指定二进制文件并附加文件,再次进行邮递但URL已从图片中删除,标头为content-type:application / octet-stream,它在邮递员中有效,但在node中不起作用。 js

enter image description here

0 个答案:

没有答案