Qiniu Seven cow problem solution
Many people react when uploading vouchers to write their own when there are many problems. Here I give you an example
Problem solution This code is a C # case, and generating tokenak,sk requires creating a seven bull account and getting it in the space secret key.
Public String GetToken () {Policy policy = new policy ("Liuhanlin-work");Policy. Deadline=1390528576;Policy. Persistentnotifyurl="";Policy. Scope="Liuhanlin-work:-123456.jpg";Policy. Persistentops="Avthumb/mp4";Policy. Scope="Liuhanlin-work";Policy. Savekey="Chrysanthemum,c_fill,w_60,h_90.jpg";Policy. Insertonly=1;Policy. Returnbody="location=$ (X:hello)";Putpolicy = Policy. ToString();System. Console. WriteLine(Putpolicy);Encodedputpolicy = setting. Bs(Putpolicy);System. Console. WriteLine(Encodedputpolicy);Encodedsign=setting. Token_sign (Encodedputpolicy);System. Console. WriteLine(encodedsign);Token = setting. AK+': '+ Encodedsign +":"+ Encodedputpolicy;Return Token;}
Signature Method Token_sign
public Static string token_sign (string s) {System.Text.Encoding Encoding = System.Text.Encoding.UTF8; byte [] Bytessk = encoding. GetBytes (SK); HMACSHA1 HMAC = new HMACSHA1 (BYTESSK); byte [] ss = Encoding. GetBytes (s); byte [] Digest = Hmac.computehash (ss); s = convert.tobase64string (digest); s = s.replace ( ' + ' , '-' ). Replace ( "/' , ' _ ' ); return s; }
Upload the code for the Policy class:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.runtime.serialization;namespace webapplication1.io{ Public classPolicy {Private stringScope =""; Public stringScope {Get{returnScope }Set{scope =value; } }PrivateInt64 deadline =0; PublicInt64 Deadline {Get{returnDeadline }Set{deadline =value; } }Private intInsertonly =0; Public intinsertonly {Get{returnInsertonly; }Set{insertonly =value; } }Private stringSavekey =""; Public stringSavekey {Get{returnSavekey; }Set{Savekey =value; } }Private stringEnduser =""; Public stringEnduser {Get{returnEnduser; }Set{Enduser =value; } }Private stringRETURNURL =""; Public stringRETURNURL {Get{returnRETURNURL; }Set{RETURNURL =value; } }Private stringReturnbody =""; Public stringReturnbody {Get{returnReturnbody; }Set{returnbody =value; } }Private stringCallbackurl =""; Public stringCallbackurl {Get{returnCallbackurl; }Set{Callbackurl =value; } }Private stringCallbackbody =""; Public stringCallbackbody {Get{returnCallbackbody; }Set{callbackbody =value; } }Private stringPersistentops =""; Public stringPersistentops {Get{returnPersistentops; }Set{Persistentops =value; } }Private stringPersistentnotifyurl =""; Public stringPersistentnotifyurl {Get{returnPersistentnotifyurl; }Set{Persistentnotifyurl =value; } }Private stringPersistentpipeline =""; Public stringPersistentpipeline {Get{returnPersistentpipeline; }Set{Persistentpipeline =value; } }Private stringMimelimit =""; Public stringMimelimit {Get{returnMimelimit; }Set{Mimelimit =value; } }Private intDetectmime =0; Public intDetectmime {Get{returnDetectmime; }Set{Detectmime =value; } }PrivateInt64 Fsizelimit =0; PublicInt64 Fsizelimit {Get{returnFsizelimit; }Set{Fsizelimit =value; } }PrivateUInt32 expires =0; PublicUInt32 Expires {Get{returnExpires }Set{expires =value; } }PrivateUInt32 Callbackfetchkey =0; PublicUInt32 Callbackfetchkey {Get{returnCallbackfetchkey; }Set{Callbackfetchkey =value; } }Private stringCallbackbodytype =""; Public stringCallbackbodytype {Get{returnCallbackbodytype; }Set{Callbackbodytype =value; } } Public Policy(stringScope, UInt32 exp =3600) {scope = scope; This. Expires = exp; This. Deadline = (UInt32) ((DateTime.Now.ToUniversalTime (). Ticks-621355968000000000)/10000000+ (Long) exp); } Public Override string ToString(){returnSetting.setjson ( This);} }}
Results Demo
The result is not demonstrated here, the code can be used directly. It has been tested countless times. Customers who need to follow this to write their own, in fact, seven cows have a very complete SDK to encapsulate most of the functionality.
SDK Address: http://developer.qiniu.com/docs/v6/sdk/
There are all kinds of languages.
Seven cows upload voucher how to write their own