public string CommitUpload(CommitBlobRequest commitRequest) { var result = BlobInformation.DefaultFileExtension; var url = commitRequest.SasUrl.Replace(blobEndpoint.ToString(), ""); var urldata = url.Split('?'); var content = urldata[0].Split('/'); var ContainerName = content[0]; var FileName = urldata[0].Replace(ContainerName + "/", ""); var accountAndKey = new StorageCredentials(AppSettings.StorageAccountName, AppSettings.StorageAccountKey); var storageaccount = new CloudStorageAccount(accountAndKey, true); var blobClient = storageaccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(ContainerName); container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); CloudBlockBlob blob = container.GetBlockBlobReference(FileName); try { if (null != commitRequest.blobParts) { blob.PutBlockList(commitRequest.blobParts); } blob.FetchAttributes(); result = blob.Properties.ContentType.Replace("image/", "").ToLower(); if (result == "jpeg") { result = BlobInformation.DefaultFileExtension; } RenameBlob(container, FileName, FileName.Replace("temp", result)); } catch (Exception ex) { //Trace.TraceError("BuildFileSasUrl throw excaption", ex.Message); } return(result); }
public string CommitUpload(CommitBlobRequest commitRequest) { var result = BlobInformation.DEFAULT_FILE_EXT; var url = commitRequest.SasUrl.Replace(blobEndpoint.ToString(), ""); var urldata = url.Split('?'); var content = urldata[0].Split('/'); var ContainerName = content[0]; var FileName = urldata[0].Replace(ContainerName + "/", ""); var accountAndKey = new StorageCredentials(AppSettings.StorageAccountName, AppSettings.StorageAccountKey); var storageaccount = new CloudStorageAccount(accountAndKey, true); var blobClient = storageaccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(ContainerName); container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); CloudBlockBlob blob = container.GetBlockBlobReference(FileName); try { if (null != commitRequest.blobParts) blob.PutBlockList(commitRequest.blobParts); //blob.Properties.ContentType = "image/jpeg"; //blob.Properties.ContentDisposition = "attachment"; //blob.SetProperties(); blob.FetchAttributes(); result = blob.Properties.ContentType.Replace("image/", "").ToLower(); if (result == "jpeg") result = BlobInformation.DEFAULT_FILE_EXT; RenameBlob(container, FileName, FileName.Replace("temp", result)); } catch (Exception ex) { //Trace.TraceError("BuildFileSasUrl throw excaption", ex.Message); } return result; }