Qiniu failed to get the upload credential through bucket: key to update the image.

Source: Internet
Author: User
I want to get the token of the file that can be updated by setting the key to bucket: key, but return the token obtained by using the following code to the android client (client android, server PHP, the client first obtains the uptoken from the server and then uploads a specific file with the token.), new... I want to get the token of the file that can be updated by setting the key to bucket: key, but return the token obtained by using the following code to the android client (client android, server PHP, the client first obtains the up token from the server and then uploads a specific file with the token.) The newly uploaded image does not overwrite the source image. Where is the problem?
Php:

        $bucket = "phpsdk";        $accessKey = QINIU_ACCESS_KEY;        $secretKey = QINIU_SECRET_KEY;        Qiniu_SetKeys($accessKey, $secretKey);        $key=$this->input->post("file_key");        if($key!=""){            $putPolicy = new Qiniu_RS_PutPolicy($bucket.":".$key);            $upToken = $putPolicy->Token(null);            echo $upToken;        }

Android:

// TmpFile is the uploaded file, key is the file name to be updated, and qiniuUploadToken is the obtained upload credential UploadManager uploadManager = new UploadManager (); uploadManager. put (tmpFile, key, qiniuUploadToken, new UpCompletionHandler () {@ Override public void complete (String key, ResponseInfo info, JSONObject response) {try {if (response! = Null) {final String actualKey = response. getString ("key"); Log. d (TAG, "get server side key =" + actualKey) ;}, new Response. errorListener () {@ Override public void onErrorResponse (VolleyError error) {}}); MessageQueue. getInstance (). addToRequestQueue (jsonObjReq, TAG);} else {Log. e (TAG, "Error from Qiniu:" + info. error) ;}} catch (JSONException e) {e. printStackTrace () ;}}, new UploadOptions (null, null, false, new UpProgressHandler () {public void progress (String key, double percent) {Log. I ("qiniu", key + "(progress):" + percent) ;}, new UpCancellationSignal () {public boolean isCancelled () {return isQiniuCancelled ;}}));

Reply content:

I want to get the token of the file that can be updated by setting the key to bucket: key, but return the token obtained by using the following code to the android client (client android, server PHP, the client first obtains the up token from the server and then uploads a specific file with the token.) The newly uploaded image does not overwrite the source image. Where is the problem?
Php:

        $bucket = "phpsdk";        $accessKey = QINIU_ACCESS_KEY;        $secretKey = QINIU_SECRET_KEY;        Qiniu_SetKeys($accessKey, $secretKey);        $key=$this->input->post("file_key");        if($key!=""){            $putPolicy = new Qiniu_RS_PutPolicy($bucket.":".$key);            $upToken = $putPolicy->Token(null);            echo $upToken;        }

Android:

// TmpFile is the uploaded file, key is the file name to be updated, and qiniuUploadToken is the obtained upload credential UploadManager uploadManager = new UploadManager (); uploadManager. put (tmpFile, key, qiniuUploadToken, new UpCompletionHandler () {@ Override public void complete (String key, ResponseInfo info, JSONObject response) {try {if (response! = Null) {final String actualKey = response. getString ("key"); Log. d (TAG, "get server side key =" + actualKey) ;}, new Response. errorListener () {@ Override public void onErrorResponse (VolleyError error) {}}); MessageQueue. getInstance (). addToRequestQueue (jsonObjReq, TAG);} else {Log. e (TAG, "Error from Qiniu:" + info. error) ;}} catch (JSONException e) {e. printStackTrace () ;}}, new UploadOptions (null, null, false, new UpProgressHandler () {public void progress (String key, double percent) {Log. I ("qiniu", key + "(progress):" + percent) ;}, new UpCancellationSignal () {public boolean isCancelled () {return isQiniuCancelled ;}}));

This may be caused by the cdn cache to overwrite the uploaded files and the accessed files are still old resources. Can you use the url? V = 20150309 access the resource. If the access is the latest resource, it indicates that the resource overwrite is successful. Generally, the cache refresh time of the resource is 10 minutes, and the whole network refresh is 24 hours, if you have high requirements on real-time resource update, You can refresh the resource url in the advanced settings of Space settings, you can also use the resource url and query parameters to access the resource.

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.