How to use HubUpload Post api?

2019-09-21 16:36发布

im looking at api opened by Microsoft Translator Hub (Microsoft Translator Hub Api Swagger Link) and i cant figure out how to use the upload file part. The other operation ive managed to do but i cant figure out how to use the HubUpload operation.

For HubUpload/Get

public void GetStatusHubUpload(string accessToken)
    {
        var client = new RestClient("https://hub.microsofttranslator.com/api/HubUpload/Get");
        var request = new RestRequest(Method.GET);
        request.AddParameter("trackingId", /*Integer*/);// Not sure where to get tracking id - after upload?
        request.AddHeader("Authorization", accessToken);
        request.AddHeader("WorkspaceIdentifierHeader", workspaceid);
        IRestResponse response = client.Execute(request);
        HubApiUploadResult hubApiUploadResult = JsonConvert.DeserializeObject<HubApiUploadResult>(response.Content);
    }

For HubUpload/Post -- How to include the excel file to be uploaded to dictionary? Whats the parameter name? Dont we need to specify the Project name as well? How does it know where to upload without giving this parameter (Inside swagger page, the only parameter specified is overwrite, Authorization and WorkspaceIdentifierHeader)?

Ive tried this one but getting internal server error

public void PostFile(string accessToken)
    {
        var client = new RestClient("https://hub.microsofttranslator.com/api/HubUpload/Post");
        var request = new RestRequest(Method.POST);
        request.AddParameter("projectname", "DemoTranslatorHub_En_Ar");
        request.AddParameter("overwrite", "false");
        request.AddHeader("Authorization", accessToken);
        request.AddHeader("WorkspaceIdentifierHeader", workspaceId);
        request.AddFile("content", @"excel file path");
        IRestResponse response = client.Execute(request);
        HubApiUploadResult hubApiUploadResult = JsonConvert.DeserializeObject<HubApiUploadResult>(response.Content);

    }

Tqvm in advanced.

1条回答
狗以群分
2楼-- · 2019-09-21 17:20

Managed to solved it. Using HttpClient and MultipartFormDataContent to handle the file upload. Need to explore more on RestSharp library and Web Api. Based on the extracted language of uploaded excel file, microsoft translator hub will place the document in its respective project. So there`s no need to place it in its own project (Specify the parameter). The tracking id will be obtain once the file is uploaded which can be used in Get method.

查看更多
登录 后发表回答