Exemplo n.º 1
0
        /// <summary>
        /// 获取一元批操作http request Body
        /// </summary>
        /// <param name="opName">操作名</param>
        /// <param name="keys">操作对象keys</param>
        /// <returns>Request Body</returns>
        private string getBatchOp_1(FileHandle op, EntryPath[] keys)
        {
            if (keys.Length < 1)
            {
                return(string.Empty);
            }
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < keys.Length - 1; i++)
            {
                string item = string.Format("op=/{0}/{1}&",
                                            OPS [(int)op],
                                            Base64URLSafe.Encode(keys [i].URI));
                sb.Append(item);
            }
            string litem = string.Format("op=/{0}/{1}", OPS [(int)op], Base64URLSafe.Encode(keys [keys.Length - 1].URI));

            return(sb.Append(litem).ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// SignRequest
        /// </summary>
        /// <param name="request"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public string SignRequest(System.Net.HttpWebRequest request, byte[] body)
        {
            Uri u = request.Address;

            using (HMACSHA1 hmac = new HMACSHA1(secretKey)) {
                string pathAndQuery      = request.Address.PathAndQuery;
                byte[] pathAndQueryBytes = Config.Encoding.GetBytes(pathAndQuery);
                using (MemoryStream buffer = new MemoryStream()) {
                    buffer.Write(pathAndQueryBytes, 0, pathAndQueryBytes.Length);
                    buffer.WriteByte((byte)'\n');
                    if (body.Length > 0)
                    {
                        buffer.Write(body, 0, body.Length);
                    }
                    byte[] digest       = hmac.ComputeHash(buffer.ToArray());
                    string digestBase64 = Base64URLSafe.Encode(digest);
                    return(this.accessKey + ":" + digestBase64);
                }
            }
        }
Exemplo n.º 3
0
        private dynamic CoverCallBack(JObject postData)
        {
            string type    = postData.Value <string>("BusinessType");
            string fileKey = postData.Value <string>("key");
            string imgPara = postData.Value <string>("imgPara");

            if (string.IsNullOrEmpty(imgPara))
            {
                return(new { key = fileKey });
            }

            string guidName             = Guid.NewGuid().ToString("N") + ".jpg";
            string thumbKey             = type + "_" + guidName;
            string thumbencodedEntryURI = Base64URLSafe.Encode(publicBucket + ":" + thumbKey);
            string thumbsaveas          = "|saveas/" + thumbencodedEntryURI;

            string pileline = GetPipeline();
            string imgFops  = imgPara + thumbsaveas;
            Pfop   pfop     = new Pfop();

            PfopDo(pfop, publicBucket, fileKey, imgFops, pileline, thumbKey, 0);


            string smallthumbKey             = type + "_small_" + guidName;
            string smallthumbencodedEntryURI = Base64URLSafe.Encode(publicBucket + ":" + smallthumbKey);
            string smallThumbsaveas          = "|saveas/" + smallthumbencodedEntryURI;

            string smallImgPara = GetSmallImageMogr2(imgPara);
            string samllImgFops = smallImgPara + smallThumbsaveas;

            pileline = GetPipeline();
            PfopDo(pfop, publicBucket, fileKey, samllImgFops, pileline, smallthumbKey, 0);

            return(new
            {
                bigKey = thumbKey,
                smallKey = smallthumbKey
            });
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="op"></param>
        /// <param name="keys"></param>
        /// <param name="force"></param>
        /// <returns></returns>
        private string getBatchOp_2(FileHandle op, EntryPathPair[] keys, bool force)
        {
            if (keys.Length < 1)
            {
                return(string.Empty);
            }
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < keys.Length - 1; i++)
            {
                string item = string.Format("op=/{0}/{1}/{2}/force/{3}/&",
                                            OPS[(int)op],
                                            Base64URLSafe.Encode(keys[i].URISrc),
                                            Base64URLSafe.Encode(keys[i].URIDest), force);
                sb.Append(item);
            }
            string litem = string.Format("op=/{0}/{1}/{2}/force/{3}", OPS[(int)op],
                                         Base64URLSafe.Encode(keys[keys.Length - 1].URISrc),
                                         Base64URLSafe.Encode(keys[keys.Length - 1].URIDest), force);

            return(sb.Append(litem).ToString());
        }
Exemplo n.º 5
0
        /// <summary>
        /// SignWithData
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        public string SignWithData(byte[] b)
        {
            string data = Base64URLSafe.Encode(b);

            return(string.Format("{0}:{1}:{2}", this.accessKey, _sign(Config.Encoding.GetBytes(data)), data));
        }