0
votes

My requirement is to Download / pull a file from azure git repo And convert it to a byte Array. I searched in Azure git repo API but I couldn't found the rest api call. Please help to get the solution.

I tried with the below url but it's returning unicode value in content object.

GET https://dev.azure.com{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&versionDescriptor.version={versionDescriptor.version}&versionDescriptor.versionType={versionDescriptor.versionType}&includeContent=true&api-version=6.0

3
Hi Harshita, Do below answers work for you? Please check it and kindly let us know the result.Edward Han-MSFT

3 Answers

0
votes

are you saying you want to use a get request from Microsoft azure? I would maybe recommend using fetch to retrieve your data. something along the lines of:

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))

I understand i'm using a post request, but if you change the subscription key, body, fetch url, and content type, you might be able to get what your are looking for. Also, you can somehow contact microsoft azure services for more help on their api.

0
votes

Have you tried this? Make sure you add httpclient to your gradle/madle build. Replace azurePathString with your 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();
}
0
votes

You could use API: https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&versionDescriptor.version={versionDescriptor.version}&download=true&api-version=6.0 to download the target file, and then read this file and convert its content to a byte Array. See: Items - Get for more details.