Exemple #1
0
        /// <summary>
        /// Delete the QiniuFile with mac.
        /// </summary>
        /// <param name="mac">Mac.</param>
        public bool Delete(MAC mac = null)
        {
            if (mac == null)
            {
                mac = new MAC();
            }
            string url = string.Format("{0}/{1}/{2}", Config.RS_HOST, "delete", Base64URLSafe.Encode(this.bucketName + ":" + this.key));

            try {
                using (QiniuWebClient client = new QiniuWebClient()) {
                    client.Call(url, mac);
                    return(true);
                }
            } catch (WebException e) {
                throw new QiniuWebException(e);
            } catch (Exception e) {
                throw e;
            }
        }
Exemple #2
0
        /// <summary>
        /// Stat the QiniuFile with mac.
        /// </summary>
        /// <param name="mac">Mac.</param>
        public QiniuFileInfo Stat(MAC mac = null)
        {
            if (mac == null)
            {
                mac = new MAC();
            }
            string url = string.Format("{0}/{1}/{2}", Config.RS_HOST, "stat", Base64URLSafe.Encode(this.bucketName + ":" + this.key));

            try {
                using (QiniuWebClient client = new QiniuWebClient()) {
                    string result = client.Call(url, mac);
                    return(GetQiniuEntry(result));
                }
            } catch (WebException e) {
                throw new QiniuWebException(e);
            }catch (Exception e) {
                throw e;
            }
        }
Exemple #3
0
        /// <summary>
        /// SignRequest
        /// </summary>
        /// <param name="request"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        public void SignRequest(System.Net.HttpWebRequest request, byte[] body)
        {
            Uri u = request.Address;

            using (HMACSHA1 hmac = new HMACSHA1(secretKey)) {
                string pathAndQuery      = request.Address.PathAndQuery;
                byte[] pathAndQueryBytes = Encoding.UTF8.GetBytes(pathAndQuery);
                using (MemoryStream buffer = new MemoryStream()) {
                    buffer.Write(pathAndQueryBytes, 0, pathAndQueryBytes.Length);
                    buffer.WriteByte((byte)'\n');
                    if (body != null && body.Length > 0)
                    {
                        buffer.Write(body, 0, body.Length);
                    }
                    byte[] digest       = hmac.ComputeHash(buffer.ToArray());
                    string digestBase64 = Base64URLSafe.Encode(digest);
                    request.Headers.Add("Authorization", "QBox " + this.accessKey + ":" + digestBase64);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Uploads the string.
        /// </summary>
        /// <param name="token">Token.</param>
        /// <param name="base64Content">Base64 content.</param>
        public void UploadString(string token, int fileSize, string mimeType, string base64Content)
        {
            using (QiniuWebClient qwc = new QiniuWebClient()) {
                qwc.UpToken = token;
                string url = Config.UP_HOST +
                             string.Format("/putb64/{0}/key/{1}/mimeType/{2}",
                                           fileSize,
                                           Base64URLSafe.Encode(this.key),
                                           Base64URLSafe.Encode(mimeType));

                qwc.UploadStringCompleted += (sender, e) => {
                    if (e.Error != null && e.Error is WebException)
                    {
                        if (e.Error is WebException)
                        {
                            QiniuWebException qwe = new QiniuWebException(e.Error as WebException);
                            onUploadFailed(new QiniuUploadFailedEventArgs(qwe));
                        }
                        else
                        {
                            onUploadFailed(new QiniuUploadFailedEventArgs(new QiniuWebException(e.Error)));
                        }
                    }
                    else
                    {
                        onQiniuUploadCompleted(new QiniuUploadCompletedEventArgs(e.Result));

                        onQiniuUploadCompleted(new QiniuUploadCompletedEventArgs(e.Result));
                    }
                };

                qwc.UploadProgressChanged += (sender, e) => {
                    onQiniuUploadProgressChanged(new QiniuUploadProgressChangedEventArgs(e.BytesSent, e.TotalBytesToSend));
                };

                qwc.Headers.Add("Content-Type", "application/octet-stream");
                qwc.UploadStringAsync(new Uri(url), "POST", base64Content);
            }
        }
Exemple #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(Encoding.UTF8.GetBytes(data)), data));
        }