<DIV id=read_tpc mb10?>FileStream theFileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
WebClient theWebClient = new WebClient();
string GMTime = DateTime.Now.ToUniversalTime().ToString("r");
MD5CryptoServiceProvider theMD5Hash = new MD5CryptoServiceProvider();
byte[] hashDatas;
hashDatas = theMD5Hash.ComputeHash(new byte[( int )theFileStream.Length]);
string contentMD5 = Convert.ToBase64String(hashDatas);
// HMACSHA1 theHMACSHA1 = new HMACSHA1();
KeyedHashAlgorithm theHMACSHA1 = KeyedHashAlgorithm.Create("HmacSHA1");
// KeyedHashAlgorithm theHMACSHA1 = KeyedHashAlgorithm.Create("1".ToUpperInvariant());
theHMACSHA1.Key = Encoding.UTF8.GetBytes("AWXbSJ07yjX0f278Hgarw2f3Z6Q=".ToCharArray());
string headerStr = "PUT\n" contentMD5 "\n" contentType "\n"
GMTime "\n" bucket "/" fileName;
byte[] rstRes = theHMACSHA1.ComputeHash(Encoding.UTF8.GetBytes(headerStr.ToCharArray()));
string strSig = Convert.ToBase64String(rstRes);
theWebClient.Headers.Add(HttpRequestHeader.Authorization, "OSS ia1lncawwinvh2vu2xjkvmdg:" strSig);
theWebClient.Headers.Add(HttpRequestHeader.ContentMd5, contentMD5);
theWebClient.Headers.Add(HttpRequestHeader.ContentType, contentType);
theWebClient.Headers.Add("X-OSS-Date", GMTime);
try
{
byte[] ret = theWebClient.UploadFile(" http冒号//storage.aliyun.com/" bucket "/" fileName, "PUT", filePath);
string strMessage = Encoding.ASCII.GetString(ret);
return strMessage;
}
catch (WebException e)
{
Stream stream = e.Response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
return reader.ReadToEnd();
}
帮忙看下。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。