Commit 6a231b8e authored by liudong1993's avatar liudong1993

阿里云oss上传文件

parent d3ef1d69
using System;
using Aliyun.OSS;
namespace COSSnippet
{
public class AliOSSUploadObject
{
/// 上传对象
public void TransferUploadFile(string filePath,string newFileName)
{
var endpoint = "<yourEndpoint>";
var accessKeyId = "<yourAccessKeyId>";
var accessKeySecret = "<yourAccessKeySecret>";
var bucketName = "<yourBucketName>";
var objectName = "<yourObjectName>";
var localFilename = "<yourLocalFilename>";
// 创建OssClient实例。
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
// 上传文件。
client.PutObject(bucketName, objectName, localFilename);
Console.WriteLine("Put object succeeded");
}
catch (Exception ex)
{
Console.WriteLine("Put object failed, {0}", ex.Message);
}
}
public void TransferUpladDel(string Key) {
var endpoint = "<yourEndpoint>";
var accessKeyId = "<yourAccessKeyId>";
var accessKeySecret = "<yourAccessKeySecret>";
var bucketName = "<yourBucketName>";
var objectName = "<yourObjectName>";
// 创建OssClient实例。
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
try
{
// 删除文件。
client.DeleteObject(bucketName, objectName);
Console.WriteLine("Delete object succeeded");
}
catch (Exception ex)
{
Console.WriteLine("Delete object failed. {0}", ex.Message);
}
}
}
}
\ No newline at end of file
......@@ -48,6 +48,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Aliyun.OSS, Version=2.11.0.0, Culture=neutral, PublicKeyToken=0ad4175f0dac0b9b, processorArchitecture=MSIL">
<HintPath>..\packages\Aliyun.OSS.SDK.2.11.0\lib\net45\Aliyun.OSS.dll</HintPath>
</Reference>
<Reference Include="Aspose.Pdf">
<HintPath>lib\Aspose.Pdf.dll</HintPath>
</Reference>
......@@ -95,6 +98,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AliOSS\TransferUploadObject.cs" />
<Compile Include="Config.cs" />
<Compile Include="DBHelper\MySqlHelper.cs" />
<Compile Include="Helper\FileDataHelper.cs" />
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Aliyun.OSS.SDK" version="2.11.0" targetFramework="net461" />
<package id="Microsoft.Diagnostics.Tracing.EventSource.Redist" version="2.2.0" targetFramework="net461" />
<package id="MySql.Data" version="8.0.14" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net461" />
......
......@@ -43,14 +43,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mall.Module.Property", "Mal
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mall.AOP", "Mall.AOP\Mall.AOP.csproj", "{231B6093-D5A7-4FEB-A624-7FACE432EA86}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestCore", "TestCore\TestCore.csproj", "{04A56FD7-DDBC-4FF9-BAC1-C4D257D35CCE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestCore", "TestCore\TestCore.csproj", "{04A56FD7-DDBC-4FF9-BAC1-C4D257D35CCE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mall.SystemSerivce", "Mall.SystemSerivce", "{646382A6-0092-441C-B202-ED8C3DE015B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mall.Education", "Mall.Education\Mall.Education.csproj", "{CE026CAA-B6E6-47F5-9998-181A07679DA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mall.EducationClient", "Mall.EducationClient\Mall.EducationClient.csproj", "{B665F9E2-C1D6-418C-9A1A-D777E3157799}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mall.Module.Education", "Mall.Module.Education\Mall.Module.Education.csproj", "{B076F66B-B75E-43DE-B305-764BF3638A91}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mall.Module.Education", "Mall.Module.Education\Mall.Module.Education.csproj", "{B076F66B-B75E-43DE-B305-764BF3638A91}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment