/* protected IHttpActionResult AzureBlobOk(AzureBlobModel azureBlob) * { * var response = Request.CreateResponse(HttpStatusCode.OK); * response.Content = new StreamContent(azureBlob.Stream); * response.Content.Headers.ContentType = new MediaTypeHeaderValue(azureBlob.ContentType); * response.Content.Headers.Add("x-filename", azureBlob.FileName); * response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); * response.Content.Headers.ContentDisposition.FileName = azureBlob.FileName; * response.Content.Headers.ContentDisposition.Size = azureBlob.FileSize; * * return ResponseMessage(response); * }*/ protected HttpResponseMessage AzureBlobOk(AzureBlobModel azureBlob) { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StreamContent(azureBlob.Stream); response.Content.Headers.ContentLength = azureBlob.FileSize; response.Content.Headers.ContentType = new MediaTypeHeaderValue(azureBlob.ContentType); response.Content.Headers.Add("x-filename", azureBlob.FileName); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentDisposition.FileName = azureBlob.FileName; response.Content.Headers.ContentDisposition.Size = azureBlob.FileSize; return(response); //var fileExtension = Path.GetExtension(azureBlob.FileName); //MemoryStream memStream = new MemoryStream(); //azureBlob.Stream.CopyTo(memStream); //var _mediaType = new MediaTypeHeaderValue(MimeTypeMap.GetMimeType(fileExtension)); //if (Request.Headers.Range != null) //{ // try // { // HttpResponseMessage partialResponse = Request.CreateResponse(HttpStatusCode.PartialContent); // partialResponse.Content = new ByteRangeStreamContent(memStream, Request.Headers.Range, _mediaType); // partialResponse.Content.Headers.ContentLength = azureBlob.FileSize; // partialResponse.Content.Headers.ContentType = new MediaTypeHeaderValue(azureBlob.ContentType); // partialResponse.Content.Headers.Add("x-filename", azureBlob.FileName); // partialResponse.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); // partialResponse.Content.Headers.ContentDisposition.FileName = azureBlob.FileName; // partialResponse.Content.Headers.ContentDisposition.Size = azureBlob.FileSize; // return partialResponse; // } // catch (InvalidByteRangeException invalidByteRangeException) // { // return Request.CreateErrorResponse(invalidByteRangeException); // } //} //else //{ // HttpResponseMessage fullResponse = Request.CreateResponse(HttpStatusCode.OK); // fullResponse.Content = new StreamContent(memStream); // //fullResponse.Content.Headers.ContentType = _mediaType; // //fullResponse.Content.Headers.Add("x-filename", azureBlob.FileName); // fullResponse.Content.Headers.ContentType = _mediaType; // fullResponse.Content.Headers.ContentLength = azureBlob.FileSize; // fullResponse.Content.Headers.Add("x-filename", azureBlob.FileName); // fullResponse.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); // fullResponse.Content.Headers.ContentDisposition.FileName = azureBlob.FileName; // fullResponse.Content.Headers.ContentDisposition.Size = azureBlob.FileSize; // return fullResponse; //} // return response; }
public async Task <AzureBlobModel> GetAzureBlob(string folderName, string fileName) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(folderName); // CloudBlockBlob blob = container.GetBlockBlobReference(fileName); var cloudBlockBlob = container.GetBlockBlobReference(fileName); var stream = await cloudBlockBlob.OpenReadAsync(); var blob = new AzureBlobModel() { FileName = fileName, FileSize = cloudBlockBlob.Properties.Length, Stream = stream, ContentType = cloudBlockBlob.Properties.ContentType }; return(blob); }