Пример #1
0
        public ActionResult SASBlobDownload(Models.BlobDownloadModel sasModel)
        {
            CloudBlobContainer container = GetCloudBlobContainer(sasModel.containerName);
            CloudBlockBlob     blob      = container.GetBlockBlobReference(sasModel.blobName);

            sasModel     = GetBlobSasUri(blob, sasModel);
            sasModel.URI = new Uri(blob.Uri + sasModel.generatedSAS);

            ViewBag.Message = sasModel.URI;

            return(View());
        }
Пример #2
0
        static BlobDownloadModel GetBlobSasUri(CloudBlockBlob blob, Models.BlobDownloadModel model)
        {
            //Set the expiry time and permissions for the blob.
            //In this case, the start time is specified as a few minutes in the past, to mitigate clock skew.
            //The shared access signature will be valid immediately.
            SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();

            sasConstraints.SharedAccessStartTime  = DateTimeOffset.UtcNow.AddMinutes(model.startTime);
            sasConstraints.SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(model.endTime);
            sasConstraints.Permissions            = SharedAccessBlobPermissions.Read; //| SharedAccessBlobPermissions.Write;

            //Generate the shared access signature on the blob, setting the constraints directly on the signature.
            model.generatedSAS = blob.GetSharedAccessSignature(sasConstraints);

            //Return the URI string for the container, including the SAS token.
            //return blob.Uri + sasBlobToken;
            return(model);
        }