Я хотел бы выполнить следующий запрос curl (php), используя Delphi 2010 и Indy10 (компонент IdHttp), но я не уверен, что это можно сделать. Я могу сделать GET, PUT и POST (CRUD) с компонентом IdHttp, но в этом случае я не знаю, как это реализовать. Меня не интересует, как имитировать команды curl с помощью Delphi, но как реализовать этот параметр c POST для загрузки файла.
$url = 'http://example.com';
$key = 'YOUR_GENERATED_API_ACCESS_KEY';
$psProductId = 19;
$urlImage = $url.'/api/images/products/'.$psProductId.'/';
//Here you set the path to the image you need to upload
$image_path = '/path/to/the/image.jpg';
$image_mime = 'image/jpg';
$args['image'] = new CurlFile($image_path, $image_mime);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_URL, $urlImage);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200 == $httpCode) {
echo 'Product image was successfully created.';
}