使用RESTAPI从azure git repo下载或拉取文件

twh00eeo  于 2021-07-09  发布在  Java
关注(0)|答案(3)|浏览(368)

我的要求是从azuregitrepo下载/拉取一个文件,并将其转换为字节数组。我在azuregitrepoapi中进行了搜索,但找不到restapi调用。请帮忙解决。
我尝试使用下面的url,但它在content对象中返回unicode值。
得到https://dev.azure.com{organization}/{project}/{api/git/repositoryid}/items?路径={path}&versiondescriptor.version={versiondescriptor.version}&versiondescriptor.versiontype={versiondescriptor.versiontype}&includecontent=true&api version=6.0

tcbh2hod

tcbh2hod1#

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

fv2wmkja

fv2wmkja2#

你是说你想使用来自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和内容类型,您就可以得到您想要的内容。此外,您还可以联系microsoft azure服务以获取有关其api的更多帮助。

qhhrdooz

qhhrdooz3#

你试过这个吗?确保添加 httpclient 为了你的gradle/madle身材。替换 azurePathString 与你的网址。

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();
}

相关问题