What should I do when I upload a file to qiniu?

Source: Internet
Author: User
I want to use qiniu to implement the offline download function. Then, extract some Encryption Algorithm functions. This is run by a shell script. The badtoken prompt is displayed. I don't know where the following script is wrong? Thank you ~ {Code...} download. php, get encodeURI, encodedEntr... want to use qiniu to implement the offline download function. Then, extract some Encryption Algorithm functions.
This is run by a shell script and prompts "bad token". I don't know where the following script is wrong?
Thank you ~

php download.php https://p.ssl.qhimg.com/t01d1f1a2ae31e3c3e4.png 111.png

Download. php, get encodeURI, encodedEntryURI, and accessToken;


  ?
  
   
\ N "$ signingStr =" {$ path }? {$ Query} \ n"; $ Sign = hmac_sha1 ($ signingStr, SecretKey); $ encodedSign = encrypt ($ sign); // $ encodeAccessKey = urlsafe_base64_encode (AccessKey ); // $ accessToken = "{$ encodeAccessKey }:{$ encodedSign}"; $ accessToken = AccessKey. ": {$ encodedSign}"; echo "AccessToken: \ r \ n {$ accessToken} \ r \ n ";
  
$ Data ['extension'] = BUCKET; $ data ['demoline'] = time () + 3600; // expiration time $ encoded = urlsafe_base64_encode (json_encode ($ data )); // $ signature = hash_hmac ('sha1', $ encoded, 'key', true); $ signature = hmac_sha1 ($ encoded, SecretKey ); $ encode_signed = urlsafe_base64_encode ($ signature); // $ UploadToken = $ encode_signed. ':'. $ encoded; $ UploadToken = AccessKey. ":". $ encode_signed. ":". $ encoded; echo "AccessToken: \ r \ n {$ UploadToken} \ r \ n"; echo "UploadURL: \ r \ nhttp: // iovip. qbox. me/fetch/{$ encodeURI}/to/{$ encodedEntryURI} \ r \ n ";

Script

sh download.sh encodeURI encodedEntryURI accessToken

Transfer Data, result... Tip:

{"error":"bad token"}

Download. sh

curl -i \     -o - \     -H 'Content-Type: application/x-www-form-urlencoded' \     -H "Authorization: QBox $3" \     -X POST \     "http://iovip.qbox.me/fetch/$1/to/$2"
The PHP part has been processed by myself (there are two errors ):

PS: I found that the last question I asked was handled by myself. I don't know if Daniel does not care about these low-tech problems, or ???
It is really incomparable with sg...


  "; Var_dump ($ signingStr); $ sign = hmac_sha1 ($ signingStr, SecretKey); $ encodedSign = sign ($ sign); var_dump ($ sign); $ accessToken = AccessKey. ": {$ encodedSign}"; echo "AccessToken: \ r \ n {$ accessToken} \ r \ n"; echo "UploadURL: \ r \ nhttp: // iovip. qbox. me/fetch/{$ encodeURI}/to/{$ encodedEntryURI} \ r \ n ";

Reply content:

I want to use qiniu to implement the offline download function. Then, extract some Encryption Algorithm functions.
This is run by a shell script and prompts "bad token". I don't know where the following script is wrong?
Thank you ~

php download.php https://p.ssl.qhimg.com/t01d1f1a2ae31e3c3e4.png 111.png

Download. php, get encodeURI, encodedEntryURI, and accessToken;


  ?
  
   
\ N "$ signingStr =" {$ path }? {$ Query} \ n"; $ Sign = hmac_sha1 ($ signingStr, SecretKey); $ encodedSign = encrypt ($ sign); // $ encodeAccessKey = urlsafe_base64_encode (AccessKey ); // $ accessToken = "{$ encodeAccessKey }:{$ encodedSign}"; $ accessToken = AccessKey. ": {$ encodedSign}"; echo "AccessToken: \ r \ n {$ accessToken} \ r \ n ";
  
$ Data ['extension'] = BUCKET; $ data ['demoline'] = time () + 3600; // expiration time $ encoded = urlsafe_base64_encode (json_encode ($ data )); // $ signature = hash_hmac ('sha1', $ encoded, 'key', true); $ signature = hmac_sha1 ($ encoded, SecretKey ); $ encode_signed = urlsafe_base64_encode ($ signature); // $ UploadToken = $ encode_signed. ':'. $ encoded; $ UploadToken = AccessKey. ":". $ encode_signed. ":". $ encoded; echo "AccessToken: \ r \ n {$ UploadToken} \ r \ n"; echo "UploadURL: \ r \ nhttp: // iovip. qbox. me/fetch/{$ encodeURI}/to/{$ encodedEntryURI} \ r \ n ";

Script

sh download.sh encodeURI encodedEntryURI accessToken

Transfer Data, result... Tip:

{"error":"bad token"}

Download. sh

curl -i \     -o - \     -H 'Content-Type: application/x-www-form-urlencoded' \     -H "Authorization: QBox $3" \     -X POST \     "http://iovip.qbox.me/fetch/$1/to/$2"
The PHP part has been processed by myself (there are two errors ):

PS: I found that the last question I asked was handled by myself. I don't know if Daniel does not care about these low-tech problems, or ???
It is really incomparable with sg...


  "; Var_dump ($ signingStr); $ sign = hmac_sha1 ($ signingStr, SecretKey); $ encodedSign = sign ($ sign); var_dump ($ sign); $ accessToken = AccessKey. ": {$ encodedSign}"; echo "AccessToken: \ r \ n {$ accessToken} \ r \ n"; echo "UploadURL: \ r \ nhttp: // iovip. qbox. me/fetch/{$ encodeURI}/to/{$ encodedEntryURI} \ r \ n ";

Previously written:AK,KEYAndscopeReplace with your

$ Data ['scope '] = 'your bucket'; $ data ['demoline'] = time () + 3600; // expiration time $ encoded = urlsafe_base64_encode (json_encode ($ data); $ signature = hash_hmac ('sha1', $ encoded, 'key', true ); $ encode_signed = urlsafe_base64_encode ($ signature); $ UploadToken = 'ak :'. $ encode_signed. ':'. $ encoded; echo $ UploadToken; function urlsafe_base64_encode ($ data) {$ data = base64_encode ($ data); $ data = str_replace (array ('+ ','/'), array ('-', '_'), $ data); return $ data ;}

Why not use the SDK?
Direct

$token = $auth->uploadToken($bucket);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.