|
@@ -348,26 +348,10 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
{
|
|
|
|
|
|
string groupName = fileSpace + "/" + folder;
|
|
|
- // string newFileName = sha1Code;
|
|
|
- // await InitializeBlob(DateTime.Now.ToString("yyyyMMdd"));
|
|
|
- blobContainer = InitializeBlob(groupName); //blobClient.GetContainerReference(groupName);
|
|
|
+ blobContainer = InitializeBlob(groupName);
|
|
|
StorageUri url = blobContainer.StorageUri;
|
|
|
string[] names = fileName.Split(".");
|
|
|
- // string name ;
|
|
|
- //for (int i = 0; i < names.Length - 1; i++)
|
|
|
- //{
|
|
|
- // name = name + names[i];
|
|
|
- //}
|
|
|
- //if (names.Length <= 1)
|
|
|
- //{
|
|
|
- // name = newFileName;
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // name = newFileName + "." + names[names.Length - 1];
|
|
|
- //}
|
|
|
- //var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
|
|
|
- //var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));
|
|
|
+
|
|
|
var blockBlob = blobContainer.GetBlockBlobReference(fileName);
|
|
|
string fileext = fileName.Substring(fileName.LastIndexOf(".") > 0 ? fileName.LastIndexOf(".") : 0);
|
|
|
if (!contentTypeDefault)
|
|
@@ -607,6 +591,62 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
// Return the URI string for the container, including the SAS token.
|
|
|
return (blobContainer.Uri.ToString(), sasContainerToken);
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 系统管理员 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
|
|
|
+ /// "system": [ "res", "item", "htex", "task", "info", "room", "exam" ],
|
|
|
+ /// 资源,题目关联,htex关联,学习活动学生上传文件关联,基本信息关联,教室平面图关联,评测冷数据关联
|
|
|
+ /// "school": [ "res", "item", "htex", "task", "info", "room", "exam" ],
|
|
|
+ /// 资源,题目关联,htex关联,学习活动关联,教师基本信息关联
|
|
|
+ /// "teacher": [ "res", "item", "htex", "task", "info" ],
|
|
|
+ /// 答案及学习活动上传的文件,学生基本信息关联
|
|
|
+ ///"student": [ "stu/{studentId}/ans", "stu/{studentId}/task" ]
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="name">容器名称</param>
|
|
|
+ /// <param name="text">文件内容的流</param>
|
|
|
+ /// <param name="folder">业务文件夹</param>
|
|
|
+ /// <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)
|
|
|
+ {
|
|
|
+
|
|
|
+ // string groupName =folder;
|
|
|
+
|
|
|
+ blobContainer = await CreateContainer(name.ToLower().Replace("#","")); //blobClient.GetContainerReference(groupName);
|
|
|
+ StorageUri url = blobContainer.StorageUri;
|
|
|
+
|
|
|
+ var blockBlob = blobContainer.GetBlockBlobReference(folder+"/"+fileName);
|
|
|
+ string fileext = fileName.Substring(fileName.LastIndexOf(".") > 0 ? fileName.LastIndexOf(".") : 0);
|
|
|
+ string content_type = "application/octet-stream";
|
|
|
+ if (!contentTypeDefault)
|
|
|
+ {
|
|
|
+ ContentTypeDict.dict.TryGetValue(fileext, out string contenttype);
|
|
|
+ if (!string.IsNullOrEmpty(contenttype))
|
|
|
+ {
|
|
|
+ blockBlob.Properties.ContentType = contenttype;
|
|
|
+ content_type = contenttype;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ blockBlob.Properties.ContentType = content_type;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ blockBlob.Properties.ContentType = content_type;
|
|
|
+ }
|
|
|
+ await blockBlob.UploadTextAsync(text);
|
|
|
+ byte[] bytes = System.Text.Encoding.Default.GetBytes(text);
|
|
|
+ AzureBlobModel model = new AzureBlobModel(fileName, _options.Container, folder, fileName, folder, blockBlob.Properties.ContentType, bytes.Length)
|
|
|
+ {
|
|
|
+ Sha1Code = ShaHashHelper.GetSHA1(bytes),
|
|
|
+ BlobUrl = url.PrimaryUri.ToString().Split("?")[0] + "/" + fileName
|
|
|
+ };
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public async Task<dynamic> GetContainerSasUri(BlobSas blobSas, bool isRead)
|
|
|
{
|
|
|
CloudBlobContainer blobContainer;
|
|
@@ -643,7 +683,7 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
// 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
|
|
|
+ Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create | SharedAccessBlobPermissions.Read| SharedAccessBlobPermissions.List
|
|
|
};
|
|
|
}
|
|
|
// Generate the shared access signature on the container, setting the constraints directly on the signature.
|