簡體   English   中英

從Azure Data Lake下載文件

[英]Download files from the azure data lake

我將文件上傳到蔚藍的數據湖中。 我嘗試通過asp.net mvc應用程序下載該文件。我具有該文件的adl路徑。 我可以下載150 MB以下的文件。 但是我無法下載超過150 MB的文件。 超時錯誤來了。

我的代碼在下面...

public ActionResult Download(string adlpath)
{
    String header = adlpath;
    Console.WriteLine(header);
    string[] splitedStr = header.Split('/');
    var path = GenerateDownloadPaths(adlpath);
    string filename = path["fileName"];
    HttpResponseMessage val = DataDownloadFile(path["fileSrcPath"]);
    byte[] filedata = val.Content.ReadAsByteArrayAsync().Result;
    string contentType = MimeMapping.GetMimeMapping(filename);
    var cd = new System.Net.Mime.ContentDisposition
    {
        FileName = filename,
        Inline = true,
    };
    Response.AppendHeader("Content-Disposition", cd.ToString());

    return File(filedata, contentType);
}

public HttpResponseMessage DataDownloadFile(string srcFilePath)
{
    string DownloadUrl = "https://{0}.azuredatalakestore.net/webhdfs/v1/{1}?op=OPEN&read=true";
    var fullurl = string.Format(DownloadUrl, _datalakeAccountName, srcFilePath);

    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesstoken.access_token);
        using (var formData = new MultipartFormDataContent())
        {
            resp = client.GetAsync(fullurl).Result;
        }
    }
    return resp;
}

圖片 :
在此處輸入圖片說明

您應該修改代碼以使用asyncawait 您的實現在檢索文件時會阻塞,這可能是超時的原因:

public async Task<HttpResponseMessage> DataDownloadFile(string srcFilePath)
{
    string DownloadUrl = "https://{0}.azuredatalakestore.net/webhdfs/v1/{1}?op=OPEN&read=true";
    var fullurl = string.Format(DownloadUrl, _datalakeAccountName, srcFilePath);

    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesstoken.access_token);
        using (var formData = new MultipartFormDataContent())
        {
            resp = await client.GetAsync(fullurl);
        }
    }
    return resp;
}

該方法的返回值更改為Task<HttpResponseMessage>並添加了async修飾符。

調用client.GetAsync更改為使用await而不是通過檢索Result屬性進行阻止。

您的代碼可能仍然超時。 我認為,在中止請求之前可以等待多長時間有可配置的限制,如果仍然超時,則應對此進行調查。

根據我的理解,您可以嘗試為HttpClient實例增加HttpClient.Timeout (默認為100秒)。

HttpClient.Timeout

獲取或設置請求超時之前要等待的時間跨度。

默認值為100,000毫秒(100秒)。

此外,如果通過Azure Web App托管應用程序,則Azure負載平衡器可能會遇到4分鍾的空閑超時設置。 您可以在Azure VM和Azure雲服務中更改空閑超時設置。 您可以在此處關注詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM