StringToSign:
PUT
YmRmM2JmMWRhMzQwNTcyNWJlNzYzNTQwZDY2MDExNDQ=
image/jpg
Mon, 02 May 2016 05:33:01 GMT
/pddtest/Hydrangeas.jpg
{"result":false,"error":"OSS API ERROR:
<?xml version="1.0" encoding="UTF-8"?>n
n
<Code>SignatureDoesNotMatch<\/Code>\n
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.<\/Message>\n
<RequestId>5726E67F58DB3AB17E9902A5<\/RequestId>\n
<HostId>oss-cn-shanghai.aliyuncs.com<\/HostId>\n
<OSSAccessKeyId>8gfnvylFKLbgBQVL<\/OSSAccessKeyId>\n
<SignatureProvided>P5jGd01TmaEawuEtzx\/x6iVYRts=<\/SignatureProvided>\n
<StringToSign>PUT\nYmRmM2JmMWRhMzQwNTcyNWJlNzYzNTQwZDY2MDExNDQ=\nimage\/jpg\nMon, 02 May 2016 05:33:01 GMT\n\/pddtest\/d41d8cd98f6714f5ba4f331db3d856465cd0a2c0a0.jpg<\/StringToSign>\n
我的代码:
$fileSize = filesize($filePath);// 函数返回指定文件的大小。为curl服务
$serverPath = $path.md5(microtime()).".jpg";//md5(uniqid(microtime()))
$uri = "/".$bucket ."/$serverPath";
//$date = gmdate('D, d M Y H:i:s GMT',strtotime('+8 hours'));//格式化 GMT/UTC 日期/时间。同 date() 函数 类似,不同的是返回的时间是格林威治标准时(GMT)。
$date = gmdate('D, d M Y H:i:s GMT');
$picturedata=fread(fopen($filePath,"r"),$fileSize);
//echo $picturedata;md5_file
$content_md5=base64_encode(md5($picturedata));
// echo $content_md5;
// $content_md5="";
//$content_type= $_FILES"image";
//echo $content_type;
$content_type="image/jpg";
$caOssHeaders="";
//$caResource='/' . str_replace(array('%2F', '%25'), array('/', '%'), rawurlencode("/".$filePath1));
$string_to_sign="PUT\n".$content_md5."n". $content_type."\n".$date."n/".$bucket."/".$filePath1;
$string_to_sign_new=utf8_encode($string_to_sign);
//$string_to_sign_new=str_replace(array("\r", "\n"), '', $string_to_sign);
//$string_to_sign_new.=rawurldecode($caResource);
echo $string_to_sign_new."n";
$sign = base64_encode(hash_hmac("sha1",$string_to_sign_new,$AcKey,true));
// echo $sign;
$ch = curl_init($up_url.$uri);
$headers = array(
"PUT /".$filePath1." HTTP/1.1",
"Content-Md5:".$content_md5,
"Content-Type: ".$content_type,
"Date: ".$date,
"Host:oss-cn-shanghai.aliyuncs.com",
"Authorization: OSS ".$AcId.":" .$sign);//HTTP 基本认证
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。