【发布时间】:2022-01-19 10:54:33
【问题描述】:
在 Azure 项目中创建附件不起作用。在开始时创建附件。但现在使用相同的代码和相同的图像在每次调用时创建黑色图像。 https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/attachments/create?view=azure-devops-rest-6.0#examples
代码示例
$data = fopen("test.png", 'rb');
$size = filesize($file);
$contents = fread($data, $size);
fclose($data);
$encodedData = base64_encode($contents);
$url = "https://dev.azure.com/OrganizationName/ProjectId/_apis/wit/attachments?fileName=test.png&uploadType=simple&api-version=6.0";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$header = array("Authorization:Basic ".base64_encode($params['username'].":".$params['token']),"Content-Type:application/octet-stream");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
if ($params['request']) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($encodedData));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
回应是
stdClass Object
(
[id] => f1f55c9e-8f48-4408-90f0-69ebb3c4d0ff
[url] => https://dev.azure.com/muhammadhaneef0757/749218ab-92a7-4ed1-86d8-738d8c3888e8/_apis/wit/attachments/f1f55c9e-8f48-4408-90f0-69ebb3c4d0ff?fileName=test.png
)
when i check url in browser there is showing black image
【问题讨论】:
标签: azure azure-devops attachment