上传文件到OSS 需要迁移
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Aliyun.OSS;
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -7,6 +8,7 @@ using SharpCompress.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
@@ -85,9 +87,13 @@ namespace IRaCIS.Core.Application.Helper
|
||||
|
||||
public interface IOSSService
|
||||
{
|
||||
public string UploadToOSS(Stream fileStream, string oosFolderPath, string fileRealName);
|
||||
public string UploadToOSS(string localFilePath, string oosFolderPath);
|
||||
|
||||
public void DownLoadFromOSS(string ossRelativePath, string localFilePath);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class OSSService : IOSSService
|
||||
{
|
||||
|
||||
@@ -107,6 +113,34 @@ namespace IRaCIS.Core.Application.Helper
|
||||
|
||||
}
|
||||
|
||||
public string UploadToOSS(Stream fileStream, string oosFolderPath,string fileRealName)
|
||||
{
|
||||
|
||||
var ossRelativePath = oosFolderPath + "/" + fileRealName;
|
||||
|
||||
try
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
fileStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
fileStream.CopyTo(memoryStream);
|
||||
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// 上传文件
|
||||
var result = _ossClient.PutObject(_OSSConfig.BucketName, ossRelativePath, memoryStream);
|
||||
}
|
||||
|
||||
|
||||
return ossRelativePath;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new BusinessValidationFailedException("oss上传失败" + ex.Message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public string UploadToOSS(string localFilePath, string oosFolderPath)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user