如何使用HubUpload Post API? [英] How to use HubUpload Post api?

查看:110
本文介绍了如何使用HubUpload Post API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在查看由Microsoft Translator Hub打开的api( Microsoft Translator Hub Api Swagger链接),我不知道如何使用上传文件部分.另一个操作香港专业教育学院设法做到了,但我不知道如何使用HubUpload操作.

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.

对于HubUpload/Get

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

对于HubUpload/Post-如何包含要上传到字典的Excel文件?参数名称是什么?我们是否也不需要指定项目名称?

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处于高级状态.

Tqvm in advanced.

推荐答案

已成功解决.使用HttpClient和MultipartFormDataContent处理文件上传.需要更多关于RestSharp库和Web Api的信息.基于上载的excel文件的提取语言,Microsoft Translator Hub会将文档放入其各自的项目中.因此,无需将其放置在自己的项目中(指定参数).文件上传后即可获取跟踪ID,该ID可在Get方法中使用.

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.

这篇关于如何使用HubUpload Post API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆