-1

我需要转换以下 cURL 命令:

curl --request PUT \
--url https://storage.bunnycdn.com/storage/path/index.jpeg \
--header 'AccessKey: <AccessKey>' \
--header 'Content-Type: application/octet-stream' \
--data-binary @/home/path/to/index.jpeg

它发送一个 put 请求,其中包含要上传到 CDN 的图像

到 https put 请求,特别是使用--data-binary

我试过了 :

   try {
                  var request = new http.MultipartRequest("PUT", uri);
                  request.headers.addAll({
                    'content-type': 'multipart/form-data',
                    'AccessKey': '<AccessKey>',
                  });

                  request.files.add(
                    await http.MultipartFile.fromPath(
                      'file',
                      _image.path,
                      filename: fileName,
                    ),

                  );

                  var response = request.send().then((value) => setState(() {
                        isLoading = false;
                      }));
                } catch (e) {
                  print(e);
                }

但不幸的是,该文件以错误的格式到达 CDN 存储。

如何使用 http put 请求作为--data-binary上传图像

4

1 回答 1

0

您可以使用邮递员将 curl 转换为某些语言,以 javascript 邮递员返回:

var request = require('request');
var options = {
  'method': 'PUT',
  'url': 'https://storage.bunnycdn.com/storage/path/index.jpeg',
  'headers': {
    'AccessKey': '<AccessKey>',
    'Content-Type': 'application/octet-stream'
  },
  body: '@/home/path/to/index.jpeg'

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

这只是一个示例,因此如果您需要更详细的内容,请执行此操作。

于 2021-10-18T18:31:34.890 回答