上传指定url文件到阿里云oss

好处是不用下载到本地,也不用删除本地文件。省事!

先下载阿里云官方代码  https://github.com/aliyun/aliyun-oss-csharp-sdk

引用其中的 aliyun-oss-sdk 项目

代码如下:

string endpoint = "http://oss-cn-beijing.aliyuncs.com";
OssClient client = new OssClient(endpoint, accessId, accessKey);
var webClient = new WebClient { Credentials = CredentialCache.DefaultCredentials };
var stream= webClient.DownloadData("http://musicdata.baidu.com/data2/pic/d59cab8d47b4ae5cd500cbb67de9cc5c/276867491/276867491.jpg");
MemoryStream ms = new MemoryStream(stream);
var r= client.PutObject("test","feng/bd.jpg", ms);//上传
var aa = r.HttpStatusCode;//ok成功

 

你可能感兴趣的:(上传指定url文件到阿里云oss)