|
@@ -17,6 +17,8 @@ using Microsoft.WindowsAzure.Storage.Shared.Protocol;
|
|
|
using TEAMModelOS.SDK.Extension.SnowFlake;
|
|
|
using TEAMModelOS.SDK.Context.Constant;
|
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
|
+using System.Runtime.Serialization.Formatters.Binary;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.JsonHelper;
|
|
|
|
|
|
namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
{
|
|
@@ -71,7 +73,7 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
// //await UploadFiles(null, new FileContainer() );
|
|
|
//}
|
|
|
|
|
|
- public async Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file,string fileSpace="common")
|
|
|
+ public async Task<List<AzureBlobModel>> UploadFiles(IFormFile[] file,string fileSpace= "common" , bool contentTypeDefault = false)
|
|
|
{
|
|
|
string groupName = fileSpace+"/" +DateTime.Now.ToString("yyyyMMdd");
|
|
|
string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
@@ -97,7 +99,6 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
// await blobClient.SetServicePropertiesAsync(serviceProperties);
|
|
|
//}
|
|
|
|
|
|
-
|
|
|
StorageUri url = blobContainer.StorageUri;
|
|
|
List<AzureBlobModel> list = new List<AzureBlobModel>();
|
|
|
foreach (FormFile f in file)
|
|
@@ -120,10 +121,13 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
var parsedContentDisposition = ContentDispositionHeaderValue.Parse(f.ContentDisposition);
|
|
|
var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));
|
|
|
var blockBlob = blobContainer.GetBlockBlobReference(name);
|
|
|
- ContentTypeDict.dict.TryGetValue(fileext, out string content_type);
|
|
|
- if (!string.IsNullOrEmpty(content_type))
|
|
|
- {
|
|
|
- blockBlob.Properties.ContentType = content_type;
|
|
|
+
|
|
|
+ if (!contentTypeDefault) {
|
|
|
+ ContentTypeDict.dict.TryGetValue(fileext, out string content_type);
|
|
|
+ if (!string.IsNullOrEmpty(content_type))
|
|
|
+ {
|
|
|
+ blockBlob.Properties.ContentType = content_type;
|
|
|
+ }
|
|
|
}
|
|
|
await blockBlob.UploadFromStreamAsync(f.OpenReadStream());
|
|
|
AzureBlobModel model = new AzureBlobModel(f, _options.Container, groupName, name)
|
|
@@ -134,7 +138,7 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
- public async Task<AzureBlobModel> UploadPath(string path, string fileSpace = "common") {
|
|
|
+ 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 = blobClient.GetContainerReference(groupName);
|
|
@@ -156,15 +160,24 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
}
|
|
|
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);
|
|
|
- ContentTypeDict.dict.TryGetValue(fileext, out string content_type);
|
|
|
- if (!string.IsNullOrEmpty(content_type))
|
|
|
+ string content_type = "application/octet-stream";
|
|
|
+ if (!contentTypeDefault)
|
|
|
{
|
|
|
- blockBlob.Properties.ContentType = content_type;
|
|
|
+ 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 {
|
|
|
- content_type = "application/octet-stream";
|
|
|
+ else
|
|
|
+ {
|
|
|
blockBlob.Properties.ContentType = content_type;
|
|
|
}
|
|
|
await blockBlob.UploadFromFileAsync(path);
|
|
@@ -177,8 +190,61 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
return model;
|
|
|
}
|
|
|
|
|
|
+ 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 = blobClient.GetContainerReference(groupName);
|
|
|
+ StorageUri url = blobContainer.StorageUri;
|
|
|
+ //FileInfo file = new FileInfo(path);
|
|
|
+ string[] names = fileName.Split(".");
|
|
|
+ string name = "";
|
|
|
+ for (int i = 0; i < names.Length - 1; i++)
|
|
|
+ {
|
|
|
+ name = name + names[i];
|
|
|
+ }
|
|
|
+ if (names.Length <= 1)
|
|
|
+ {
|
|
|
+ name = fileName + "_" + newFileName;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ name = name + "_" + newFileName + "." + names[names.Length - 1];
|
|
|
+ }
|
|
|
+ var blockBlob = blobContainer.GetBlockBlobReference(name);
|
|
|
+ // var parsedContentDisposition = ContentDispositionHeaderValue.Parse("form-data; name=\"files\"; filename=\"" + file.Name + "\"");
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ string objStr = obj.ToJson();
|
|
|
+ long length = System.Text.Encoding.Default.GetBytes(objStr).Length;
|
|
|
+ await blockBlob.UploadTextAsync(objStr);
|
|
|
+ //var provider = new FileExtensionContentTypeProvider();
|
|
|
+ //var memi = provider.Mappings[fileext];
|
|
|
+ AzureBlobModel model = new AzureBlobModel(fileName, _options.Container, groupName, name, content_type , length)
|
|
|
+ {
|
|
|
+ BlobUrl = url.PrimaryUri.ToString().Split("?")[0] + "/" + name
|
|
|
+ };
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- public async Task<AzureBlobModel> UploadWord(IFormFile file, string fileSpace = "wordfiles")
|
|
|
+ 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;
|
|
@@ -203,6 +269,15 @@ namespace TEAMModelOS.SDK.Module.AzureBlob.Implements
|
|
|
var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
|
|
|
var filename = Path.Combine(parsedContentDisposition.FileName.Trim('"'));
|
|
|
var blockBlob = blobContainer.GetBlockBlobReference(name);
|
|
|
+ string fileext = filename.Substring(filename.LastIndexOf(".") > 0 ? filename.LastIndexOf(".") : 0);
|
|
|
+ if (!contentTypeDefault)
|
|
|
+ {
|
|
|
+ ContentTypeDict.dict.TryGetValue(fileext, out string content_type);
|
|
|
+ if (!string.IsNullOrEmpty(content_type))
|
|
|
+ {
|
|
|
+ blockBlob.Properties.ContentType = content_type;
|
|
|
+ }
|
|
|
+ }
|
|
|
await blockBlob.UploadFromStreamAsync(file.OpenReadStream());
|
|
|
AzureBlobModel model = new AzureBlobModel(file, _options.Container, groupName, name)
|
|
|
{
|