簡體   English   中英

將 cURL 命令轉換為 http put 請求

[英]convert cURL command to http put request

我需要轉換以下 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

它發送帶有要上傳到 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

您可以使用郵遞員將 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);
});

這只是一個例子,所以如果你需要更詳細的東西,那就去做吧。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM