Ejemplo n.º 1
0
        /// <summary>
        /// Creates the put HTTP request.
        /// </summary>
        /// <param name="actionCredential">The action credential.</param>
        /// <param name="contentType">Type of the content.</param>
        /// <returns></returns>
        public static HttpWebRequest CreatePutHttpRequest(this BinaryStorageActionCredential actionCredential, string contentType = null)
        {
            var result = CreateHttpRequest(actionCredential, HttpConstants.HttpMethod.Put);

            if (result != null)
            {
                result.SafeSetHttpHeader("x-ms-blob-content-type", contentType.SafeToString(HttpConstants.ContentType.BinaryDefault));
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// To the HTTP request.
        /// </summary>
        /// <param name="actionCredential">The action credential.</param>
        /// <param name="httpMethod">The HTTP method.</param>
        /// <returns></returns>
        public static HttpWebRequest CreateHttpRequest(this BinaryStorageActionCredential actionCredential, string httpMethod = HttpConstants.HttpMethod.Get)
        {
            if (actionCredential != null)
            {
                var httpRequest = actionCredential.CredentialUri.CreateHttpWebRequest(httpMethod);
                httpRequest.Headers.Set("x-ms-blob-type", "BlockBlob");

                return(httpRequest);
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Clouds the content of the BLOB file.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="downloadCredential">The download credential.</param>
        /// <param name="contentType">Type of the content.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static ActionResult CloudBlobFileResult(this Controller controller, BinaryStorageActionCredential downloadCredential, string contentType = null, string fileName = null)
        {
            if (controller != null && downloadCredential != null && !string.IsNullOrWhiteSpace(downloadCredential.CredentialUri))
            {
                var httpRequest = downloadCredential.CredentialUri.CreateHttpWebRequest();
                var stream      = httpRequest.GetResponse().GetResponseStream();

                if (!string.IsNullOrWhiteSpace(fileName))
                {
                    controller.Response.SafeSetHttpHeader(HttpConstants.HttpHeader.ContentDisposition, fileName);
                }

                return(new FileStreamResult(stream, contentType.SafeToString(HttpConstants.ContentType.BinaryDefault)));
            }

            return(new EmptyResult());
        }