使用rest api从azure git repo下载或提取文件



我的要求是从azure git repo下载/提取一个文件,并将其转换为字节数组。我在Azure git repo API中搜索,但找不到rest API调用。请帮助获取解决方案。

我尝试使用下面的url,但它在内容对象中返回unicode值。

得到https://dev.azure.com{organization}/{project}/_apis/git/repositoryId}/items?path={path}&versionDescriptor.version={versionDescriptor.version}&versionDescriptor.versionType={versionDescriptor.versionType}&includeContent=true&api版本=6.0

您是说要使用Microsoft azure的get请求吗?我可能会建议使用fetch来检索您的数据。类似的东西

fetch("https://westus.api.cognitive.microsoft.com/face/v1.0/detect? returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=emotion&recognitionModel= 
recognition_01&returnRecognitionModel=false&detectionModel=detection_01"
, {
method: 'post',
headers: {
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': '<subscription key>'
},
body: makeblob(contents)
}).then((response) => response.json()).then(success => {
that.setState({selectedFile: url1});
that.setState({facesArray: success});
console.log("facesArray is", that.state.facesArray);
console.log("new selected state is", that.state.selectedFile);
// console.log(success);
}).catch(error =>
console.log("did not work ",error))

我知道我使用的是post请求,但如果你更改订阅密钥、正文、获取url和内容类型,你可能会得到你想要的。此外,您可以以某种方式联系microsoftazure服务,以获取有关其api的更多帮助。

你试过这个吗?确保将httpclient添加到渐变/疯狂构建中。将azurePathString替换为您的URL。

public byte[] executeBinary(URI uri) throws IOException, ClientProtocolException {
HttpGet httpget = new HttpGet(azurePathString);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
entity.writeTo(baos);
return baos.toByteArray();
}

您可以使用API:https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&versionDescriptor.version={versionDescriptor.version}&download=true&api-version=6.0下载目标文件,然后读取该文件并将其内容转换为字节数组。有关更多详细信息,请参阅:项目-获取。

最新更新