/// <summary> /// Generates a service request to download the binary contents of a file based on an item ID. /// </summary> /// <param name="itemReference"></param> /// <param name = "options"></param> /// <returns></returns> public async Task<Stream> DownloadStreamForItemAsync(ODItemReference itemReference, StreamDownloadOptions options) { if (!itemReference.IsValid()) throw new ArgumentException("ItemReference was invalid. Requires either an ID or Path"); Uri serviceUri = UriForItemReference(itemReference, ApiConstants.ContentRelationshipName); var request = await CreateHttpRequestAsync(serviceUri, ApiConstants.HttpGet); options.ModifyRequest(request); var response = await GetHttpResponseAsync(request); if (response.StatusCode == System.Net.HttpStatusCode.Found) { Uri downloadUri = new Uri(response.Headers[ApiConstants.LocationHeaderName]); request = await CreateHttpRequestAsync(downloadUri, ApiConstants.HttpGet); options.ModifyRequest(request); response = await GetHttpResponseAsync(request); } var responseStream = await response.GetResponseStreamAsync(); return responseStream; }
/// <summary> /// Returns a stream for the contents of an item. /// </summary> /// <param name="item"></param> /// <param name="connection"></param> /// <returns></returns> public static async Task<System.IO.Stream> GetContentStreamAsync(this ODItem item, ODConnection connection, StreamDownloadOptions downloadOptions) { return await connection.DownloadStreamForItemAsync(item.ItemReference(), downloadOptions); }
/// <summary> /// Returns a stream for the contents of an item. /// </summary> /// <param name="item"></param> /// <param name="connection"></param> /// <returns></returns> public static async Task <System.IO.Stream> GetContentStreamAsync(this ODItem item, ODConnection connection, StreamDownloadOptions downloadOptions) { return(await connection.DownloadStreamForItemAsync(item.ItemReference(), downloadOptions)); }
/// <summary> /// Generates a service request to download the binary contents of a file based on an item ID. /// </summary> /// <param name="itemReference"></param> /// <param name = "options"></param> /// <returns></returns> public async Task <Stream> DownloadStreamForItemAsync(ODItemReference itemReference, StreamDownloadOptions options) { if (!itemReference.IsValid()) { throw new ArgumentException("ItemReference was invalid. Requires either an ID or Path"); } Uri serviceUri = UriForItemReference(itemReference, ApiConstants.ContentRelationshipName); var request = await CreateHttpRequestAsync(serviceUri, ApiConstants.HttpGet); options.ModifyRequest(request); var response = await GetHttpResponseAsync(request); if (response.StatusCode == System.Net.HttpStatusCode.Found) { Uri downloadUri = new Uri(response.Headers[ApiConstants.LocationHeaderName]); request = await CreateHttpRequestAsync(downloadUri, ApiConstants.HttpGet); options.ModifyRequest(request); response = await GetHttpResponseAsync(request); } var responseStream = await response.GetResponseStreamAsync(); return(responseStream); }