/// <summary> /// Call the B2 'Download File By Name' API (see https://www.backblaze.com/b2/docs/b2_download_file_by_name.html) /// </summary> /// <param name="downloadUrl"></param> /// <param name="authorizationToken"></param> /// <param name="bucketName"></param> /// <param name="fileName"></param> /// <param name="rangeLower"></param> /// <param name="rangeUpper"></param> /// <returns></returns> public async Task <B2File> DownloadFileByName(string downloadUrl, string authorizationToken, string bucketName, string fileName, long?rangeLower = null, long?rangeUpper = null) { Trace(() => $"DownloadFileByName: downloadUrl={downloadUrl}, authorizationToken={authorizationToken}, bucketName={bucketName}, fileName={fileName}, rangeLower={rangeLower}, rangeUpper={rangeUpper}"); var request = new HttpRequestMessage(HttpMethod.Get, $"{downloadUrl}/file/{bucketName}/{fileName}") .WithAuthorization(authorizationToken) .WithRange(rangeLower, rangeUpper); var response = await httpClient.SendAsync(request).ConfigureAwait(false); var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); ThrowIfFailure(response, responseStream); var f = new B2File(responseStream, response.Headers, response.Content.Headers); Trace(() => $"DownloadFileByName completed: id={f.id}, name={f.name}, length={f.length}, contentType={f.contentType}, sha1={f.sha1}, attributes=[{ToString(f.attributes)}]"); return(f); }
/// <summary> /// Call the B2 'Download File By ID' API (see https://www.backblaze.com/b2/docs/b2_download_file_by_id.html) /// </summary> /// <param name="apiUrl"></param> /// <param name="authorizationToken"></param> /// <param name="rangeLower"></param> /// <param name="rangeUpper"></param> /// <param name="fileId"></param> /// <returns></returns> public async Task <B2File> DownloadFileById(string downloadUrl, string authorizationToken, string fileId, long?rangeLower = null, long?rangeUpper = null) { Trace(() => $"DownloadFileById: downloadUrl={downloadUrl}, authorizationToken={authorizationToken}, fileId={fileId}, rangeLower={rangeLower}, rangeUpper={rangeUpper}"); var request = new HttpRequestMessage(HttpMethod.Post, $"{downloadUrl}/b2api/v2/b2_download_file_by_id") .WithAuthorization(authorizationToken) .WithJsonSerializedContent(new DownloadFileByIdRequest { fileId = fileId }) .WithRange(rangeLower, rangeUpper); var response = await httpClient.SendAsync(request).ConfigureAwait(false); var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); ThrowIfFailure(response, responseStream); var f = new B2File(responseStream, response.Headers, response.Content.Headers); Trace(() => $"DownloadFileById completed: id={f.id}, name={f.name}, length={f.length}, contentType={f.contentType}, sha1={f.sha1}, attributes=[{ToString(f.attributes)}]"); return(f); }