i need to convert the following cURL command:
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
which sends a put request with an image to be uploaded to a CDN
to an https put request, specially with the --data-binary
i tried :
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);
}
but unfortunately the file arrives at the CDN storage with wrong formatting.
how can i upload the image with http put request as --data-binary
You can use postman to convert curl to some languages, to javascript postman return this:
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);
});
This is just a example, so if you need something more elaborated do it.