You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Microsoft Translator Hub的HubUpload Post API及查询上传状态

How to Use the Microsoft Translator Hub's HubUpload/Get API

Since you’ve already got the hang of the other Translator Hub APIs, let’s break down exactly how to use the HubUpload/Get endpoint to track your file upload status.

First, a quick clarification: this API exists to check the progress or outcome of an asynchronous file upload task to the Hub. Uploading files isn’t instant, so you’ll need this endpoint to confirm if your upload succeeded, is still processing, or failed.

Step 1: Get Your trackingId First

You can’t call HubUpload/Get out of nowhere—you need to initiate a file upload via another HubUpload endpoint (like HubUpload/Create or the upload initiation API first). When you send that initial upload request, the response will include a unique integer trackingId—this is the key value you’ll pass to HubUpload/Get.

Step 2: Implement the Status Check (Refined Code)

Here’s a polished version of your sample code with critical details your original snippet missed, plus error handling:

public async Task<string> CheckHubUploadStatusAsync(string accessToken, int trackingId)
{
    using var client = new RestClient("https://hub.microsofttranslator.com/api/HubUpload/Get");
    var request = new RestRequest(Method.GET);

    // Mandatory: Add authentication header (your original code omitted this!)
    request.AddHeader("Authorization", $"Bearer {accessToken}");
    
    // Add the tracking ID from your initial upload request
    request.AddParameter("trackingId", trackingId);

    try
    {
        var response = await client.ExecuteAsync(request);
        
        if (response.IsSuccessful)
        {
            // The response body will have status details (e.g., JSON or plain text)
            // Common status values: "InProgress", "Completed", "Failed"
            return $"Upload Status: {response.Content}";
        }
        else
        {
            return $"Status check failed: {response.StatusCode} - {response.ErrorMessage}";
        }
    }
    catch (Exception ex)
    {
        return $"Error checking status: {ex.Message}";
    }
}

Key Things to Remember:

  • Authentication is non-negotiable: You must include the Authorization header with your Bearer token. Without this, you’ll get an unauthorized error every time.
  • trackingId is unique per upload: Store this value right after you start the upload—you can’t track a task without it.
  • Poll for status if needed: If the response returns InProgress, wait 10-30 seconds and call the endpoint again until you get a final status (Completed or Failed).
  • Parse the response content: Depending on your request setup, the response might be a simple status string or a JSON object with more details (like error messages if the upload failed).

Typical Workflow:

  1. Call the Hub upload initiation API (e.g., HubUpload/Create) to start uploading your file, save the returned trackingId.
  2. Wait a short delay, then call HubUpload/Get with the trackingId.
  3. If status is InProgress, repeat the check after a few seconds.
  4. Once you get Completed or Failed, handle the result (e.g., start training a model if successful, debug the error if failed).

内容的提问来源于stack exchange,提问作者Sam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:23:53