How to buffer an HTTP response using the request module?

前端 未结 4 806
清酒与你
清酒与你 2021-02-01 18:52

I would like to stream the contents of an HTTP response to a variable. My goal is to get an image via request(), and store it in in MongoDB - but the image is alway

4条回答
  •  一生所求
    2021-02-01 19:30

    var options = {
        headers: {
            'Content-Length': contentLength,
            'Content-Type': 'application/octet-stream'
        },
        url: 'http://localhost:3000/lottery/lt',
        body: formData,
        encoding: null, // make response body to Buffer.
        method: 'POST'
    };
    

    set encoding to null, return Buffer.

提交回复
热议问题