|
@@ -103,7 +103,6 @@ namespace TEAMModelOS.SDK.DI
|
|
BlobContainerClient blobContainer = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName);
|
|
BlobContainerClient blobContainer = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName);
|
|
|
|
|
|
var blockBlob = blobContainer.GetBlobClient($"{root}/{blobpath}");
|
|
var blockBlob = blobContainer.GetBlobClient($"{root}/{blobpath}");
|
|
-
|
|
|
|
string content_type = "application/octet-stream";
|
|
string content_type = "application/octet-stream";
|
|
if (!contentTypeDefault)
|
|
if (!contentTypeDefault)
|
|
{
|
|
{
|
|
@@ -113,16 +112,6 @@ namespace TEAMModelOS.SDK.DI
|
|
{
|
|
{
|
|
content_type = contenttype;
|
|
content_type = contenttype;
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- //blockBlob.Properties.ContentType = content_type;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- //blockBlob.Properties.ContentType = content_type;
|
|
|
|
}
|
|
}
|
|
byte[] bytes = System.Text.Encoding.Default.GetBytes(json);
|
|
byte[] bytes = System.Text.Encoding.Default.GetBytes(json);
|
|
Stream streamBlob = new MemoryStream(bytes);
|
|
Stream streamBlob = new MemoryStream(bytes);
|
|
@@ -148,45 +137,24 @@ namespace TEAMModelOS.SDK.DI
|
|
/// <param name="fileName">文件名</param>
|
|
/// <param name="fileName">文件名</param>
|
|
/// <param name="contentTypeDefault">是否存放文件后缀对应的contentType</param>
|
|
/// <param name="contentTypeDefault">是否存放文件后缀对应的contentType</param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public static async Task<AzureBlobModel> UploadFileByContainer(this AzureStorageFactory azureStorage, string name, Stream stream, string folder, string fileName, bool contentTypeDefault = true)
|
|
|
|
|
|
+ public static async Task<string> UploadFileByContainer(this AzureStorageFactory azureStorage, string name, Stream stream, string root, string blobpath, bool contentTypeDefault = true)
|
|
{
|
|
{
|
|
-
|
|
|
|
- // string groupName =folder;
|
|
|
|
-
|
|
|
|
BlobContainerClient blobContainer = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName);
|
|
BlobContainerClient blobContainer = azureStorage.GetBlobContainerClient(name.ToLower().Replace("#", "")); //blobClient.GetContainerReference(groupName);
|
|
Uri url = blobContainer.Uri;
|
|
Uri url = blobContainer.Uri;
|
|
-
|
|
|
|
- var blockBlob = blobContainer.GetBlobClient(folder + "/" + fileName);
|
|
|
|
- string fileext = fileName.Substring(fileName.LastIndexOf(".") > 0 ? fileName.LastIndexOf(".") : 0);
|
|
|
|
|
|
+ var blockBlob = blobContainer.GetBlobClient($"{root}/{blobpath}");
|
|
string content_type = "application/octet-stream";
|
|
string content_type = "application/octet-stream";
|
|
if (!contentTypeDefault)
|
|
if (!contentTypeDefault)
|
|
{
|
|
{
|
|
|
|
+ string fileext = blobpath.Substring(blobpath.LastIndexOf(".") > 0 ? blobpath.LastIndexOf(".") : 0);
|
|
ContentTypeDict.dict.TryGetValue(fileext, out string contenttype);
|
|
ContentTypeDict.dict.TryGetValue(fileext, out string contenttype);
|
|
if (!string.IsNullOrEmpty(contenttype))
|
|
if (!string.IsNullOrEmpty(contenttype))
|
|
{
|
|
{
|
|
content_type = contenttype;
|
|
content_type = contenttype;
|
|
-
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- //blockBlob.Properties.ContentType = content_type;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- //blockBlob.Properties.ContentType = content_type;
|
|
|
|
- }
|
|
|
|
await blockBlob.UploadAsync(stream, true);
|
|
await blockBlob.UploadAsync(stream, true);
|
|
blockBlob.SetHttpHeaders(new BlobHttpHeaders { ContentType = content_type });
|
|
blockBlob.SetHttpHeaders(new BlobHttpHeaders { ContentType = content_type });
|
|
- AzureBlobModel model = new AzureBlobModel(fileName, name, folder, fileName, folder, content_type, stream.Length)
|
|
|
|
- {
|
|
|
|
- Sha1Code = ShaHashHelper.GetSHA1(stream),
|
|
|
|
- BlobUrl = blockBlob.Uri.ToString()
|
|
|
|
- };
|
|
|
|
- return model;
|
|
|
|
|
|
+ return blockBlob.Uri.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|