简体   繁体   English

如何使用 npm 将文件发布到远程 url?

[英]How to post a file to a remote url using npm got?

I'm trying to post a file to a remote URL using npm got.我正在尝试使用 npm 将文件发布到远程 URL。 But it is not working as expected.但它没有按预期工作。

I have tried the following我尝试了以下

const headers = {
    "Content-Type": "image/png"
}

const requestProperties = {
    method: 'POST',
    url,
    headers,
    json: fs.createReadStream(file.path)
}

const response = await got(requestProperties);

Thank you!谢谢!

Thank you @phil I have used body property instead of json.谢谢@phil我使用了 body 属性而不是 json。

const headers = {
    "Content-Type": "image/png"
}

const requestProperties = {
    method: 'POST',
    url,
    headers,
    body: fs.createReadStream(file.path)
}

const response = await got(requestProperties);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM