示例#1
0
        /// <summary>
        /// Uploads the small file ( < 8MB).
        /// </summary>
        /// <param name="token">Token.</param>
        private void uploadSmallFile(string token)
        {
            if (uploading)
            {
                return;
            }
            uploading = true;
            NameValueCollection formData = new NameValueCollection();

            formData ["key"]   = this.key;
            formData ["token"] = token;
            try {
                using (QiniuWebClient qwc = new QiniuWebClient()) {
                    qwc.UploadDataCompleted += (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));
                        }
                    };
                    qwc.UploadProgressChanged += (sender, e) => {
                        onQiniuUploadProgressChanged(new QiniuUploadProgressChangedEventArgs(e.BytesSent, e.TotalBytesToSend));
                    };
                    qwc.AsyncPostForm(Config.UP_HOST, formData, this.localfile);
                }
            } catch (WebException we) {
                onUploadFailed(new QiniuUploadFailedEventArgs(new QiniuWebException(we)));
            } catch (Exception e) {
                onUploadFailed(new QiniuUploadFailedEventArgs(new QiniuWebException(e)));
            } finally {
                uploading = false;
            }
        }
示例#2
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);
            }
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="qiniu.QiniuUploadFailedEventArgs"/> class.
 /// </summary>
 /// <param name="e">E.</param>
 public QiniuUploadFailedEventArgs(QiniuWebException e)
 {
     this.error = e;
 }