Seven Qiniu Storage--Memory put example (Go SDK)

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

Nothing to say, incredibly there is a document, git why not provide example?

I look at the code, pondering a bit, the original is to be so used. We have to spit out the name of the package, why go to IO? Golang comes with the System package name is Io Ah, brother.

Download package from Git online, go get-u github.com/qiniu/api

Then, paste the code:

Package Mainimport ("Bufio"    "FMT"    . "github.com/qiniu/api/conf"Qnio"Github.com/qiniu/api/io"    "Github.com/qiniu/api/rs"    "OS") Func main () {Access_key="xxxxxxxx"Secret_key="xxxxxxxx"    varret Qnio. PutretvarExtra = &Qnio. putextra{MimeType:"IMAGE/JEPG", CHECKCRC:0,} key:="1024x1024.jpg"Scope:= Fmt. Sprintf ("skypixeltest:%s", key) Putpolicy:=Rs. putpolicy{Scope:scope,//Expires:expires,} Uptoken:=Putpolicy.token (nil) fi, err:= OS. Open ("/users/qpzhang/downloads/1024x1024.jpg") St, _:=fi. Stat ()ifErr! =Nil {panic (ERR)} defer fi. Close () Data:=Bufio. Newreader (FI) fmt. Println ("size", St. Size ()) Err= Qnio. Put2 (Nil, &ret, Uptoken, key, data, St. Size (), extra)ifErr! =Nil {fmt. PRINTLN (ERR)}Else{fmt. Println ("put sucess ...", ret)}}

The description of scope refers to the official:
Http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html

And then spit it out, stating that the document and the variable name are different. The description document is a variable name in JSON.

Type Putpolicystruct{Scopestring' JSON:"Scope"' Expires uint32 ' JSON:"deadline"`//Cut-off time (in seconds)Insertonly uint16 ' JSON:"Exclusive,omitempty"`//if not 0, even if the scope is Bucket:key, insert onlyDetectmime uint16 ' JSON:"Detectmime,omitempty"`//if not 0, the server is automatically determined based on the content MimeTypeFsizelimit Int64 ' JSON:"Fsizelimit,omitempty"' Savekeystring' JSON:"Savekey,omitempty"' Callbackurlstring' JSON:"Callbackurl,omitempty"' Callbackbodystring' JSON:"Callbackbody,omitempty"' ReturnUrlstring' JSON:"Returnurl,omitempty"' Returnbodystring' JSON:"Returnbody,omitempty"' Persistentopsstring' JSON:"Persistentops,omitempty"' Persistentnotifyurlstring' JSON:"Persistentnotifyurl,omitempty"' Persistentpipelinestring' JSON:"Persistentpipeline,omitempty"' Asyncopsstring' JSON:"Asyncops,omitempty"' Enduserstring' JSON:"Enduser,omitempty"`}

 

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.