admin管理员组文章数量:1122833
I am using the following code to make the request by native fetch
.
const blob = new Blob([content], {type: 'text/plain'});
const file = new File([blob], buildFileName(fileName));
const data = new FormData();
data.append('file', file);
data.append(
'pinataMetadata',
JSON.stringify({name: buildFileName(fileName)})
);
data.append('pinataOptions', JSON.stringify({cidVersion: 1}));
const res = await fetch('/pinning/pinFileToIPFS', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PUB_PINATA_JWT}`,
},
body: data as any,
});
This errors out with:
Invalid request format.
I even tried setting content-type manually in the headers above:
'Content-Type': 'multipart/form-data'
But then, it fails with Boundary Not Found
.
Then, I switched to using fetch
from undici
library and it worked right away even without setting the content type header.
Unfortunatelly, I don't want to use undici
because I don't want to use many libraries. I am using node 20 but also tried this for node 18.
Why does it work with undici
's fetch but not with native fetch ?
本文标签: javascriptNodejs Invalid request format when using fetchStack Overflow
版权声明:本文标题:javascript - Node.js Invalid request format when using fetch - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736302872a1931688.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论