Seven Qiniu storage list List file simple demo (PHP version and Golang demo)

Source: Internet
Author: User
Tags hmac sha1
This is a creation in Article, where the information may have evolved or changed.

See the seven cattle online many ask the list this API how to use? or people can not understand, I use a simple example or demo to simple to see you
How to use this! A PHP version of a Golang simple demo!

golang版本

Package Mainimport ("Crypto/hmac" "Crypto/sha1" "Encoding/base64" "FMT" "Io/ioutil" "Net/http" "Stri    NGS ") const (SK =" D-K57TE5HPE3KREXFTXLWFKML2XBQEKA-MTKRUFB "AK =" Kun6xyzloatid2mjhm90-6vfy2m7hc90ijdh4uor " HOST = "rsf.qbox.me") func main () {mac: = HMAC. New (SHA1. New, []byte (SK)) Mac. Write ([]byte ("/list?bucket=gitwiduu&limit=20\n")) A: = Mac. Sum (nil) Client: = &http. client{} u: = base64. Stdencoding.encodetostring ([]byte (a)) U = Strings. Replace (U, "+", "-",-1) u = strings. Replace (U, "/", "_",-1) Request, _: = http. Newrequest ("POST", "http://rsf.qbox.me/list?bucket=gitwiduu&limit=20", nil) request. Header.set ("Content-type", "application/x-www-form-urlencoded; Param=value ") request. Header.set ("host", host) request. Header.set ("Connection", "keep-alive") request. Header.set ("Authorization", "QBox" +ak+ ":" +u) Response, _: = client. Do (request) if response. StatusCode = = $ {data, _: = Ioutil. ReaDAll (response. Body) fmt. PRINTLN (String data)} FMT. Println ("OK")}

PHP version

<?php/* * +----------------------------------------------------------------------* | Seven Cows list file * +----------------------------------------------------------------------* | Author:widuu <admin@widuu.com> * +----------------------------------------------------------------------* | time:09/11/2014 * +----------------------------------------------------------------------***/require (' conf.php ') ;d efine (' Akey ', $accessKey);d efine (' SKEY ', $secretKey);d efine (' BUCKET ', $bucket); class qiniu_list{Private $QINIU _    Rsf_host = ' http://rsf.qbox.me ';    Private $header = Array ();    private $url = ';    private static $instance; Private Function __construct () {}//single-state mode instantiation public static function getinstance () {if (!isset (self:: $instance)            ) {$c = __class__;        Self:: $instance = new $c;    } return Self:: $instance; }/** * @param prefix prefix * @param marker tag * @param limit number of occurrences * **/public Function g Eturl ($Prefix= ", $marker =", $limit = 0) {$query = @array (' bucket ' = bucket);        if (!empty ($prefix)) {$query [' prefix '] = $prefix;        } if (!empty ($marker)) {$query [' marker '] = $marker;        } if (!empty ($limit)) {$query [' limit '] = $limit; } $url = '/list? '.        Http_build_query ($query);    $this->url = $url;        }//Get token Private Function GetToken ($url) {$find = array (' + ', '/');        $replace = Array ('-', ' _ '); $sign = Hash_hmac (' SHA1 ', $this->url. "        \ n ", SKEY, True); $result = Akey. ':' .        Str_replace ($find, $replace, Base64_encode ($sign));     return $result;                 }/** * @Description list Files * @return Array (* [' marker '] = + tag, * [' item '] = = array of file list *) **/public Function Listfiles () {$_post_url = Trim ($this->q         Iniu_rsf_host. $this->url, ' \ n '); $curl = curl_inIt ();        curl_setopt ($curl, Curlopt_url, $_post_url);        $this->header[] = ' Host:rsf.qbox.me ';        $this->header[] = ' content-type:application/x-www-form-urlencoded ';           $this->header[] = ' authorization:qbox '. $this->gettoken ($this->url);        curl_setopt ($curl, Curlopt_header, false);        curl_setopt ($curl, Curlopt_httpheader, $this->header);         curl_setopt ($curl, Curlopt_ssl_verifypeer, false);         curl_setopt ($curl, Curlopt_ssl_verifyhost, false);        curl_setopt ($curl, Curlopt_post, true);          curl_setopt ($curl, Curlopt_returntransfer, true);           curl_setopt ($curl, Curlopt_postfields, "");          $result = curl_exec ($curl);          Curl_close ($curl);      Return Json_decode ($result, true); }}//Demo Method $qiniu_list = Qiniu_list::getinstance (); $Qiniu _list, GetUrl (', ', '); echo "<pre>";p Rint_r ($ Qiniu_list, Listfiles ()); echo "</pre>";

without permission, do not reprint this site any article: Micro network» Seven qiniu storage List List file simple demo (PHP version and Golang demo)

Related Article

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.