问题描述
需求是上传一张图片到我们的对象存储服务器。
对方给了接口协议
post 请求
Content-Type 为 multipart/form-data
form-data, key = "filecontent",value = 图片内容
之前自己用 node.js 写过,几行代码搞定,以为没啥问题,结果用 Golang 遇到了坑
node.js
node.js 发送请求,只需要这几行
const options = {
method: "POST", url: "xxxxxxxxxxxxx", headers: {
"Content-Type": "multipart/form-data" }, timeout: 3000, formData: {
// key:filecontent value:stream "filecontent": fs.createReadStream(zip_file_path) } }; request(options, function (err, res, body) {
if (err) {
console.log(err); } else {
let data = JSON.parse(body); if (data.e