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"`}