|
@@ -32,7 +32,7 @@
|
|
|
// public AzureBlobDBRepository(IConfiguration configuration, IWebHostEnvironment env, AzureBlobOptions options, AzureBlobOptions azureBlobOptions)
|
|
|
// {
|
|
|
// Configuration = configuration;
|
|
|
-// // BaseConfigModel.SetBaseConfig(Configuration, env.ContentRootPath, env.WebRootPath);
|
|
|
+// // BaseConfigModel.SetBaseConfig(Configuration, env.ContentRootPath, env.WebRootPath);
|
|
|
// _options = options;
|
|
|
// if (!string.IsNullOrEmpty(options.ConnectionString))
|
|
|
// {
|
|
@@ -43,33 +43,33 @@
|
|
|
|
|
|
// public AzureBlobDBRepository()
|
|
|
// {
|
|
|
-
|
|
|
+
|
|
|
|
|
|
// }
|
|
|
|
|
|
-// private CloudBlobContainer InitializeBlob(string container)
|
|
|
+// private CloudBlobContainer InitializeBlob(string container)
|
|
|
// {
|
|
|
// //https://teammodelstorage.blob.core.chinacloudapi.cn/wechatfilescontainer
|
|
|
-
|
|
|
-// // Type t = typeof(T);
|
|
|
-// //若要将权限设置为仅针对 blob 的公共读取访问,请将 PublicAccess 属性设置为 BlobContainerPublicAccessType.Blob。
|
|
|
-// //要删除匿名用户的所有权限,请将该属性设置为 BlobContainerPublicAccessType.Off。
|
|
|
-// blobContainer = blobClient.GetContainerReference(_options .Container+"/"+ container);
|
|
|
-
|
|
|
-// // await blobContainer.CreateIfNotExistsAsync();
|
|
|
-// // BlobContainerPermissions permissions = await blobContainer.GetPermissionsAsync();
|
|
|
-// // permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
|
|
|
-// // await blobContainer.SetPermissionsAsync(permissions);
|
|
|
-
|
|
|
+
|
|
|
+// // Type t = typeof(T);
|
|
|
+// //若要将权限设置为仅针对 blob 的公共读取访问,请将 PublicAccess 属性设置为 BlobContainerPublicAccessType.Blob。
|
|
|
+// //要删除匿名用户的所有权限,请将该属性设置为 BlobContainerPublicAccessType.Off。
|
|
|
+// blobContainer = blobClient.GetContainerReference(_options.Container + "/" + container);
|
|
|
+
|
|
|
+// // await blobContainer.CreateIfNotExistsAsync();
|
|
|
+// // BlobContainerPermissions permissions = await blobContainer.GetPermissionsAsync();
|
|
|
+// // permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
|
|
|
+// // await blobContainer.SetPermissionsAsync(permissions);
|
|
|
+
|
|
|
// return blobContainer;
|
|
|
// }
|
|
|
|
|
|
-// public async Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file,string fileSpace= "common" , bool contentTypeDefault = false)
|
|
|
+// public async Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file, string fileSpace = "common", bool contentTypeDefault = false)
|
|
|
// {
|
|
|
-// string groupName = fileSpace+"/" +DateTime.Now.ToString("yyyyMMdd");
|
|
|
+// string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd");
|
|
|
// string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
// // await InitializeBlob(DateTime.Now.ToString("yyyyMMdd"));
|
|
|
-// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
+// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
// //var serviceProperties = await blobClient.GetServicePropertiesAsync();
|
|
|
// //var corsSettings = serviceProperties.Cors;
|
|
|
// //var corsRule = corsSettings.CorsRules.FirstOrDefault(
|
|
@@ -94,25 +94,28 @@
|
|
|
// List<AzureBlobModel> list = new List<AzureBlobModel>();
|
|
|
// foreach (FormFile f in file)
|
|
|
// {
|
|
|
-
|
|
|
+
|
|
|
// string[] names = f.FileName.Split(".");
|
|
|
// string name = "";
|
|
|
-// for (int i = 0; i < names.Length-1; i++) {
|
|
|
+// for (int i = 0; i < names.Length - 1; i++)
|
|
|
+// {
|
|
|
// name = name + names[i];
|
|
|
// }
|
|
|
// if (names.Length <= 1)
|
|
|
// {
|
|
|
// name = f.FileName + "_" + newFileName;
|
|
|
// }
|
|
|
-// else {
|
|
|
+// else
|
|
|
+// {
|
|
|
// name = name + "_" + newFileName + "." + names[names.Length - 1];
|
|
|
// }
|
|
|
-// string fileext = f.FileName.Substring(f.FileName.LastIndexOf(".")>0? f.FileName.LastIndexOf("."):0);
|
|
|
-
|
|
|
+// string fileext = f.FileName.Substring(f.FileName.LastIndexOf(".") > 0 ? f.FileName.LastIndexOf(".") : 0);
|
|
|
+
|
|
|
// var parsedContentDisposition = ContentDispositionHeaderValue.Parse(f.ContentDisposition);
|
|
|
// var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));
|
|
|
// var blockBlob = blobContainer.GetBlockBlobReference(name);
|
|
|
-// if (!contentTypeDefault) {
|
|
|
+// if (!contentTypeDefault)
|
|
|
+// {
|
|
|
// ContentTypeDict.dict.TryGetValue(fileext, out string content_type);
|
|
|
// if (!string.IsNullOrEmpty(content_type))
|
|
|
// {
|
|
@@ -120,7 +123,7 @@
|
|
|
// }
|
|
|
// }
|
|
|
// await blockBlob.UploadFromStreamAsync(f.OpenReadStream());
|
|
|
-// string sha1= ShaHashHelper.GetSHA1(f.OpenReadStream());
|
|
|
+// string sha1 = ShaHashHelper.GetSHA1(f.OpenReadStream());
|
|
|
// AzureBlobModel model = new AzureBlobModel(f, _options.Container, groupName, name)
|
|
|
// {
|
|
|
// BlobUrl = url.PrimaryUri.ToString().Split("?")[0] + "/" + name,
|
|
@@ -130,10 +133,11 @@
|
|
|
// }
|
|
|
// return list;
|
|
|
// }
|
|
|
-// public async Task<AzureBlobModel> UploadPath(string path, string fileSpace = "common" , bool contentTypeDefault = false) {
|
|
|
+// public async Task<AzureBlobModel> UploadPath(string path, string fileSpace = "common", bool contentTypeDefault = false)
|
|
|
+// {
|
|
|
// string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd");
|
|
|
// string newFileName = DateTime.Now.ToString("HHmmssfffffff");
|
|
|
-// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
+// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
// StorageUri url = blobContainer.StorageUri;
|
|
|
// FileInfo file = new FileInfo(path);
|
|
|
// string[] names = file.Name.Split(".");
|
|
@@ -152,7 +156,7 @@
|
|
|
// }
|
|
|
// string fileext = file.Name.Substring(file.Name.LastIndexOf(".") > 0 ? file.Name.LastIndexOf(".") : 0);
|
|
|
|
|
|
-// // var parsedContentDisposition = ContentDispositionHeaderValue.Parse("form-data; name=\"files\"; filename=\"" + file.Name + "\"");
|
|
|
+// // var parsedContentDisposition = ContentDispositionHeaderValue.Parse("form-data; name=\"files\"; filename=\"" + file.Name + "\"");
|
|
|
// var blockBlob = blobContainer.GetBlockBlobReference(name);
|
|
|
// string content_type = "application/octet-stream";
|
|
|
// if (!contentTypeDefault)
|
|
@@ -175,9 +179,9 @@
|
|
|
// await blockBlob.UploadFromFileAsync(path);
|
|
|
// //var provider = new FileExtensionContentTypeProvider();
|
|
|
// //var memi = provider.Mappings[fileext];
|
|
|
-// AzureBlobModel model = new AzureBlobModel(file, _options.Container, groupName, name , content_type)
|
|
|
+// AzureBlobModel model = new AzureBlobModel(file, _options.Container, groupName, name, content_type)
|
|
|
// {
|
|
|
-// Sha1Code=ShaHashHelper.GetSHA1(file.Create()),
|
|
|
+// Sha1Code = ShaHashHelper.GetSHA1(file.Create()),
|
|
|
// BlobUrl = url.PrimaryUri.ToString().Split("?")[0] + "/" + name
|
|
|
// };
|
|
|
// return model;
|
|
@@ -189,7 +193,7 @@
|
|
|
// {
|
|
|
// string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd");
|
|
|
// string newFileName = DateTime.Now.ToString("HHmmssfffffff");
|
|
|
-// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
+// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
// StorageUri url = blobContainer.StorageUri;
|
|
|
// //FileInfo file = new FileInfo(path);
|
|
|
// string[] names = fileName.Split(".");
|
|
@@ -227,8 +231,8 @@
|
|
|
// {
|
|
|
// blockBlob.Properties.ContentType = content_type;
|
|
|
// }
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
// await blockBlob.UploadTextAsync(text);
|
|
|
// byte[] bytes = System.Text.Encoding.Default.GetBytes(text);
|
|
|
// //var provider = new FileExtensionContentTypeProvider();
|
|
@@ -241,11 +245,11 @@
|
|
|
// return model;
|
|
|
// }
|
|
|
|
|
|
-// public async Task<AzureBlobModel> UploadObject(string fileName,object obj, string fileSpace = "common", bool contentTypeDefault =true)
|
|
|
+// public async Task<AzureBlobModel> UploadObject(string fileName, object obj, string fileSpace = "common", bool contentTypeDefault = true)
|
|
|
// {
|
|
|
// string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd");
|
|
|
// string newFileName = DateTime.Now.ToString("HHmmssfffffff");
|
|
|
-// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
+// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
// StorageUri url = blobContainer.StorageUri;
|
|
|
// //FileInfo file = new FileInfo(path);
|
|
|
// string[] names = fileName.Split(".");
|
|
@@ -279,16 +283,17 @@
|
|
|
// blockBlob.Properties.ContentType = content_type;
|
|
|
// }
|
|
|
// }
|
|
|
-// else {
|
|
|
+// else
|
|
|
+// {
|
|
|
// blockBlob.Properties.ContentType = content_type;
|
|
|
// }
|
|
|
// string objStr = obj.ToJsonAbs();
|
|
|
-
|
|
|
+
|
|
|
// await blockBlob.UploadTextAsync(objStr);
|
|
|
// //var provider = new FileExtensionContentTypeProvider();
|
|
|
// //var memi = provider.Mappings[fileext];
|
|
|
// byte[] bytes = System.Text.Encoding.Default.GetBytes(objStr);
|
|
|
-// AzureBlobModel model = new AzureBlobModel(fileName, _options.Container, groupName, name, content_type , bytes.Length)
|
|
|
+// AzureBlobModel model = new AzureBlobModel(fileName, _options.Container, groupName, name, content_type, bytes.Length)
|
|
|
// {
|
|
|
// Sha1Code = ShaHashHelper.GetSHA1(bytes),
|
|
|
// BlobUrl = url.PrimaryUri.ToString().Split("?")[0] + "/" + name
|
|
@@ -299,11 +304,11 @@
|
|
|
|
|
|
// public async Task<AzureBlobModel> UploadFile(IFormFile file, string fileSpace = "wordfiles", bool contentTypeDefault = true)
|
|
|
// {
|
|
|
-// long bizno= IdWorker.getInstance().NextId();
|
|
|
-// string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd")+"/"+ bizno;
|
|
|
+// long bizno = IdWorker.getInstance().NextId();
|
|
|
+// string groupName = fileSpace + "/" + DateTime.Now.ToString("yyyyMMdd") + "/" + bizno;
|
|
|
// string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
// // await InitializeBlob(DateTime.Now.ToString("yyyyMMdd"));
|
|
|
-// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
+// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
// StorageUri url = blobContainer.StorageUri;
|
|
|
// string[] names = file.FileName.Split(".");
|
|
|
// string name = "";
|
|
@@ -334,22 +339,22 @@
|
|
|
// await blockBlob.UploadFromStreamAsync(file.OpenReadStream());
|
|
|
// string sha1 = ShaHashHelper.GetSHA1(file.OpenReadStream());
|
|
|
// AzureBlobModel model = new AzureBlobModel(file, _options.Container, groupName, name)
|
|
|
-// {
|
|
|
-// Sha1Code=sha1,
|
|
|
+// {
|
|
|
+// Sha1Code = sha1,
|
|
|
// BlobUrl = url.PrimaryUri.ToString().Split("?")[0] + "/" + name
|
|
|
// };
|
|
|
// return model;
|
|
|
// }
|
|
|
|
|
|
|
|
|
-// public AzureBlobModel UploadFileByFolderNAsyn(Stream fileSteam, string folder, string fileName, string fileSpace = "pptx", bool contentTypeDefault = true)
|
|
|
+// public AzureBlobModel UploadFileByFolderNAsyn(Stream fileSteam, string folder, string fileName, string fileSpace = "pptx", bool contentTypeDefault = true)
|
|
|
// {
|
|
|
|
|
|
// string groupName = fileSpace + "/" + folder;
|
|
|
-// blobContainer = InitializeBlob(groupName);
|
|
|
+// blobContainer = InitializeBlob(groupName);
|
|
|
// StorageUri url = blobContainer.StorageUri;
|
|
|
// string[] names = fileName.Split(".");
|
|
|
-
|
|
|
+
|
|
|
// var blockBlob = blobContainer.GetBlockBlobReference(fileName);
|
|
|
// string fileext = fileName.Substring(fileName.LastIndexOf(".") > 0 ? fileName.LastIndexOf(".") : 0);
|
|
|
// if (!contentTypeDefault)
|
|
@@ -364,7 +369,7 @@
|
|
|
// blockBlob.Properties.ContentType = "application/octet-stream";
|
|
|
// }
|
|
|
// }
|
|
|
-// blockBlob.UploadFromStreamAsync(fileSteam).GetAwaiter().GetResult() ;
|
|
|
+// blockBlob.UploadFromStreamAsync(fileSteam).GetAwaiter().GetResult();
|
|
|
// AzureBlobModel model = new AzureBlobModel(fileName, _options.Container, groupName, fileName, folder, blockBlob.Properties.ContentType, fileSteam.Length)
|
|
|
// {
|
|
|
// Sha1Code = ShaHashHelper.GetSHA1(fileSteam),
|
|
@@ -379,14 +384,14 @@
|
|
|
|
|
|
// public async Task<AzureBlobModel> UploadFileByFolder(Stream fileSteam, string folder, string fileName, string fileSpace = "pptx", bool contentTypeDefault = true)
|
|
|
// {
|
|
|
-
|
|
|
+
|
|
|
// string groupName = fileSpace + "/" + folder;
|
|
|
-// // string newFileName = sha1Code;
|
|
|
+// // string newFileName = sha1Code;
|
|
|
// // await InitializeBlob(DateTime.Now.ToString("yyyyMMdd"));
|
|
|
-// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
+// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
// StorageUri url = blobContainer.StorageUri;
|
|
|
// string[] names = fileName.Split(".");
|
|
|
-// // string name ;
|
|
|
+// // string name ;
|
|
|
// //for (int i = 0; i < names.Length - 1; i++)
|
|
|
// //{
|
|
|
// // name = name + names[i];
|
|
@@ -410,7 +415,8 @@
|
|
|
// {
|
|
|
// blockBlob.Properties.ContentType = content_type;
|
|
|
// }
|
|
|
-// else {
|
|
|
+// else
|
|
|
+// {
|
|
|
// blockBlob.Properties.ContentType = "application/octet-stream";
|
|
|
// }
|
|
|
// }
|
|
@@ -428,9 +434,9 @@
|
|
|
// public async Task<AzureBlobModel> UploadTextByFolder(string text, string folder, string fileName, string fileSpace = "pptx", bool contentTypeDefault = true)
|
|
|
// {
|
|
|
// string groupName = fileSpace + "/" + folder;
|
|
|
-// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
+// blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
// StorageUri url = blobContainer.StorageUri;
|
|
|
-
|
|
|
+
|
|
|
// var blockBlob = blobContainer.GetBlockBlobReference(fileName);
|
|
|
// string fileext = fileName.Substring(fileName.LastIndexOf(".") > 0 ? fileName.LastIndexOf(".") : 0);
|
|
|
// string content_type = "application/octet-stream";
|
|
@@ -452,7 +458,7 @@
|
|
|
// blockBlob.Properties.ContentType = content_type;
|
|
|
// }
|
|
|
|
|
|
-
|
|
|
+
|
|
|
// await blockBlob.UploadTextAsync(text);
|
|
|
// byte[] bytes = System.Text.Encoding.Default.GetBytes(text);
|
|
|
// AzureBlobModel model = new AzureBlobModel(fileName, _options.Container, groupName, fileName, folder, blockBlob.Properties.ContentType, bytes.Length)
|
|
@@ -470,15 +476,15 @@
|
|
|
// /// <param name="container">A reference to the container.</param>
|
|
|
// /// <param name="policyName">The name of the stored access policy.</param>
|
|
|
// public async Task<bool> CreateSharedAccessPolicyAsync(string policyName,
|
|
|
-// string containerName = null)
|
|
|
+// string containerName = null)
|
|
|
// {
|
|
|
-
|
|
|
+
|
|
|
// blobContainer = await CreateContainer(_options.Container);
|
|
|
// //Create a new shared access policy and define its constraints.
|
|
|
// SharedAccessBlobPolicy sharedPolicy = new SharedAccessBlobPolicy()
|
|
|
// {
|
|
|
// SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(15),
|
|
|
-// Permissions = SharedAccessBlobPermissions.Delete
|
|
|
+// Permissions = SharedAccessBlobPermissions.Delete
|
|
|
// };
|
|
|
|
|
|
// //Get the container's existing permissions.
|
|
@@ -500,14 +506,14 @@
|
|
|
// /// <param name="container">A reference to the container.</param>
|
|
|
// /// <param name="policyName">The name of the stored access policy.</param>
|
|
|
// public async Task DeleteSharedAccessPolicyAsync(string policyName,
|
|
|
-// string containerName = null)
|
|
|
+// string containerName = null)
|
|
|
// {
|
|
|
-
|
|
|
+
|
|
|
// blobContainer = await CreateContainer(_options.Container);
|
|
|
// BlobContainerPermissions permissions = await blobContainer.GetPermissionsAsync();
|
|
|
// permissions.SharedAccessPolicies.Remove(policyName);
|
|
|
// await blobContainer.SetPermissionsAsync(permissions);
|
|
|
-
|
|
|
+
|
|
|
// }
|
|
|
|
|
|
|
|
@@ -522,7 +528,7 @@
|
|
|
// public async Task<(string, string, string)> GetContainerSasUri(string containerName = null, string storedPolicyName = null)
|
|
|
// {
|
|
|
// string sasContainerToken;
|
|
|
-
|
|
|
+
|
|
|
// blobContainer = await CreateContainer(_options.Container);
|
|
|
// // If no stored policy is specified, create a new access policy and define its constraints.
|
|
|
// if (storedPolicyName == null)
|
|
@@ -535,7 +541,7 @@
|
|
|
// // Omitting the start time for a SAS that is effective immediately helps to avoid clock skew.
|
|
|
// SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
|
|
|
// SharedAccessExpiryTime = DateTime.UtcNow.AddHours(2),
|
|
|
-// Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create| SharedAccessBlobPermissions.Read
|
|
|
+// Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Read
|
|
|
// };
|
|
|
|
|
|
// // Generate the shared access signature on the container, setting the constraints directly on the signature.
|
|
@@ -552,8 +558,8 @@
|
|
|
// }
|
|
|
|
|
|
// // Return the URI string for the container, including the SAS token.
|
|
|
-
|
|
|
-// return (blobContainer.Uri.Scheme+ "://"+ blobContainer.Uri.Host.ToString() , blobContainer.Name, sasContainerToken);
|
|
|
+
|
|
|
+// return (blobContainer.Uri.Scheme + "://" + blobContainer.Uri.Host.ToString(), blobContainer.Name, sasContainerToken);
|
|
|
// }
|
|
|
// public async Task<(string, string)> GetContainerSasUriRead(string containerName, string storedPolicyName = null)
|
|
|
// {
|
|
@@ -571,7 +577,7 @@
|
|
|
// // Omitting the start time for a SAS that is effective immediately helps to avoid clock skew.
|
|
|
// SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
|
|
|
// SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1),
|
|
|
-// Permissions = SharedAccessBlobPermissions.Read
|
|
|
+// Permissions = SharedAccessBlobPermissions.Read
|
|
|
// };
|
|
|
|
|
|
// // Generate the shared access signature on the container, setting the constraints directly on the signature.
|
|
@@ -606,15 +612,15 @@
|
|
|
// /// <param name="fileName">文件名</param>
|
|
|
// /// <param name="contentTypeDefault">是否存放文件后缀对应的contentType</param>
|
|
|
// /// <returns></returns>
|
|
|
-// public async Task<AzureBlobModel> UploadFileByContainer(string name ,string text, string folder, string fileName, bool contentTypeDefault = true)
|
|
|
+// public async Task<AzureBlobModel> UploadFileByContainer(string name, string text, string folder, string fileName, bool contentTypeDefault = true)
|
|
|
// {
|
|
|
|
|
|
-// // string groupName =folder;
|
|
|
+// // string groupName =folder;
|
|
|
|
|
|
-// blobContainer = await CreateContainer(name.ToLower().Replace("#","")); //blobClient.GetContainerReference(groupName);
|
|
|
+// blobContainer = await CreateContainer(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName);
|
|
|
// StorageUri url = blobContainer.StorageUri;
|
|
|
|
|
|
-// var blockBlob = blobContainer.GetBlockBlobReference(folder+"/"+fileName);
|
|
|
+// var blockBlob = blobContainer.GetBlockBlobReference(folder + "/" + fileName);
|
|
|
// string fileext = fileName.Substring(fileName.LastIndexOf(".") > 0 ? fileName.LastIndexOf(".") : 0);
|
|
|
// string content_type = "application/octet-stream";
|
|
|
// if (!contentTypeDefault)
|
|
@@ -674,31 +680,34 @@
|
|
|
// Permissions = SharedAccessBlobPermissions.Read
|
|
|
// };
|
|
|
// }
|
|
|
-// else {
|
|
|
+// else
|
|
|
+// {
|
|
|
// adHocPolicy = new SharedAccessBlobPolicy()
|
|
|
// {
|
|
|
// // When the start time for the SAS is omitted, the start time is assumed to be the time when the storage service receives the request.
|
|
|
// // Omitting the start time for a SAS that is effective immediately helps to avoid clock skew.
|
|
|
// SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
|
|
|
// SharedAccessExpiryTime = dateTime,
|
|
|
-// Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Read| SharedAccessBlobPermissions.List
|
|
|
+// Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List
|
|
|
// };
|
|
|
// }
|
|
|
// // Generate the shared access signature on the container, setting the constraints directly on the signature.
|
|
|
-// string sasContainerToken = blobContainer.GetSharedAccessSignature(adHocPolicy, null);
|
|
|
-
|
|
|
-// return new BlobAuth { url = blobContainer.Uri.AbsoluteUri.Replace(blobContainer.Uri.AbsolutePath,""), sas = sasContainerToken, timeout = time,name = blobContainer.Name };
|
|
|
+// string sasContainerToken = blobContainer.GetSharedAccessSignature(adHocPolicy, null);
|
|
|
+
|
|
|
+// return new BlobAuth { url = blobContainer.Uri.AbsoluteUri.Replace(blobContainer.Uri.AbsolutePath, ""), sas = sasContainerToken, timeout = time, name = blobContainer.Name };
|
|
|
// }
|
|
|
-// public async Task<Dictionary<string,object>> GetBlobSasUri(BlobSas blobSas,bool isRead) {
|
|
|
+// public async Task<Dictionary<string, object>> GetBlobSasUri(BlobSas blobSas, bool isRead)
|
|
|
+// {
|
|
|
// string sasBlobToken;
|
|
|
|
|
|
// CloudBlobContainer blobContainer;
|
|
|
// if (blobSas.role == "system")
|
|
|
// {
|
|
|
-// blobContainer = await CreateContainer(_options.Container);
|
|
|
+// blobContainer = await CreateContainer(_options.Container);
|
|
|
// }
|
|
|
-// else {
|
|
|
-// blobContainer = await CreateContainer(blobSas.name.ToLower().Replace("#",""));
|
|
|
+// else
|
|
|
+// {
|
|
|
+// blobContainer = await CreateContainer(blobSas.name.ToLower().Replace("#", ""));
|
|
|
// }
|
|
|
// // Create a new access policy and define its constraints.
|
|
|
// // Note that the SharedAccessBlobPolicy class is used both to define the parameters of an ad hoc SAS, and
|
|
@@ -733,10 +742,13 @@
|
|
|
// List<string> folders = BaseConfigModel.Configuration.GetSection("Azure:Blob:" + blobSas.role).Get<List<string>>();
|
|
|
// if (folders.IsNotEmpty())
|
|
|
// {
|
|
|
-// foreach (string floder in folders) {
|
|
|
+// foreach (string floder in folders)
|
|
|
+// {
|
|
|
// string cates = floder;
|
|
|
-// if (blobSas.role == "student") {
|
|
|
-// if (string.IsNullOrEmpty(blobSas.code)) {
|
|
|
+// if (blobSas.role == "student")
|
|
|
+// {
|
|
|
+// if (string.IsNullOrEmpty(blobSas.code))
|
|
|
+// {
|
|
|
// throw new BizException("请设置学生编码!", ResponseCode.PARAMS_ERROR);
|
|
|
// }
|
|
|
// cates = floder.Replace("{studentId}", blobSas.code);
|
|
@@ -746,13 +758,13 @@
|
|
|
// CloudBlockBlob blob = blobContainer.GetBlockBlobReference(cates);
|
|
|
// // Generate the shared access signature on the blob, setting the constraints directly on the signature.
|
|
|
// sasBlobToken = blob.GetSharedAccessSignature(adHocSAS);
|
|
|
-// dict.Add(cates, new { url=blob.Uri,sas=sasBlobToken , timeout = time });
|
|
|
+// dict.Add(cates, new { url = blob.Uri, sas = sasBlobToken, timeout = time });
|
|
|
// }
|
|
|
// }
|
|
|
// return dict;
|
|
|
// }
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
// /// <summary>
|
|
|
// /// 若要为 blob 创建服务 SAS,请调用 CloudBlob.GetSharedAccessSignature 方法。
|
|
@@ -762,14 +774,14 @@
|
|
|
// /// <param name="blobName"></param>
|
|
|
// /// <param name="policyName"></param>
|
|
|
// /// <returns></returns>
|
|
|
-// public async Task<string> GetBlobSasUri(string blobName, string containerName=null, string policyName = null)
|
|
|
+// public async Task<string> GetBlobSasUri(string blobName, string containerName = null, string policyName = null)
|
|
|
// {
|
|
|
// string sasBlobToken;
|
|
|
-
|
|
|
-// blobContainer =await CreateContainer(_options.Container);
|
|
|
+
|
|
|
+// blobContainer = await CreateContainer(_options.Container);
|
|
|
// // Get a reference to a blob within the container.
|
|
|
// // Note that the blob may not exist yet, but a SAS can still be created for it.
|
|
|
-// CloudBlockBlob blob = blobContainer.GetBlockBlobReference( blobName );
|
|
|
+// CloudBlockBlob blob = blobContainer.GetBlockBlobReference(blobName);
|
|
|
// if (policyName == null)
|
|
|
// {
|
|
|
// // Create a new access policy and define its constraints.
|
|
@@ -781,7 +793,7 @@
|
|
|
// // Omitting the start time for a SAS that is effective immediately helps to avoid clock skew.
|
|
|
// SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
|
|
|
// SharedAccessExpiryTime = DateTime.UtcNow.AddHours(2),
|
|
|
-// Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Read
|
|
|
+// Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Read
|
|
|
// };
|
|
|
|
|
|
// // Generate the shared access signature on the blob, setting the constraints directly on the signature.
|
|
@@ -808,7 +820,7 @@
|
|
|
// return blobProperties;
|
|
|
// }
|
|
|
|
|
|
-// public List<BlobFileDto> GetBlobProperties(List<BlobFileDto> blobProperties, CloudBlobDirectory blobDirectory)
|
|
|
+// public List<BlobFileDto> GetBlobProperties(List<BlobFileDto> blobProperties, CloudBlobDirectory blobDirectory)
|
|
|
// {
|
|
|
// IEnumerable<IListBlobItem> listBlobItems1 = blobDirectory.ListBlobsSegmentedAsync(new BlobContinuationToken()).GetAwaiter().GetResult().Results;
|
|
|
// foreach (IListBlobItem listBlobItem in listBlobItems1)
|
|
@@ -849,7 +861,7 @@
|
|
|
// {
|
|
|
// SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-15),
|
|
|
// SharedAccessExpiryTime = DateTime.UtcNow.AddHours(2),
|
|
|
-// Permissions = SharedAccessBlobPermissions.Read
|
|
|
+// Permissions = SharedAccessBlobPermissions.Read
|
|
|
// };
|
|
|
// sasBlobToken = blob.GetSharedAccessSignature(adHocSAS);
|
|
|
|
|
@@ -877,7 +889,7 @@
|
|
|
// return new BlobAuth { url = blob.Uri.ToString(), sas = sasBlobToken, timeout = time };
|
|
|
// }
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
// private async Task<CloudBlobContainer> CreateContainer(string containerName)
|
|
|
// {
|
|
@@ -893,16 +905,17 @@
|
|
|
// CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
|
|
|
// CloudBlobContainer container = blobClient.GetContainerReference(containerName);
|
|
|
// bool a = await container.ExistsAsync();
|
|
|
-// if (!a) {
|
|
|
-// throw new BizException("容器不存在!",ResponseCode.PARAMS_ERROR);
|
|
|
+// if (!a)
|
|
|
+// {
|
|
|
+// throw new BizException("容器不存在!", ResponseCode.PARAMS_ERROR);
|
|
|
// }
|
|
|
-// // await container.CreateIfNotExistsAsync();
|
|
|
+// // await container.CreateIfNotExistsAsync();
|
|
|
// return container;
|
|
|
// }
|
|
|
|
|
|
// public async Task Deleteblob(string azureBlobSAS)
|
|
|
// {
|
|
|
-
|
|
|
+
|
|
|
// (string, string) a = BlobUrlString(azureBlobSAS);
|
|
|
// string ContainerName = a.Item1;
|
|
|
// string BlobName = a.Item2;
|
|
@@ -918,11 +931,13 @@
|
|
|
// }
|
|
|
// // await DeleteSharedAccessPolicyAsync(PolicyName);
|
|
|
// }
|
|
|
-// catch (Exception e) {
|
|
|
+// catch (Exception e)
|
|
|
+// {
|
|
|
|
|
|
// throw new BizException(e.StackTrace);
|
|
|
// }
|
|
|
-// finally {
|
|
|
+// finally
|
|
|
+// {
|
|
|
// await DeleteSharedAccessPolicyAsync(PolicyName);
|
|
|
// }
|
|
|
// }
|