예제 #1
0
        /// <summary>
        /// 上传数据
        /// </summary>
        /// <param name="data">待上传的数据</param>
        /// <param name="saveKey">要保存的文件名称</param>
        /// <param name="token">上传凭证</param>
        /// <returns>上传文件后的返回结果</returns>
        public HttpResult UploadData(byte[] data, string saveKey, string token)
        {
            HttpResult result = new HttpResult();

            if (data.Length > PUT_THRESHOLD)
            {
                ResumableUploader ru = new ResumableUploader(UPLOAD_FROM_CDN);
                result = ru.UploadData(data, saveKey, token, null);
            }
            else
            {
                FormUploader fu = new FormUploader(UPLOAD_FROM_CDN);
                result = fu.UploadData(data, saveKey, token);
            }

            return(result);
        }
예제 #2
0
        public void UploadDataTest()
        {
            Mac mac = new Mac(AccessKey, SecretKey);

            byte[] data = File.ReadAllBytes(LocalFile2);
            string key  = FileKey2;

            PutPolicy putPolicy = new PutPolicy();

            putPolicy.Scope = Bucket1 + ":" + key;
            putPolicy.SetExpires(3600);
            putPolicy.DeleteAfterDays = 1;
            string token = Auth.CreateUploadToken(mac, putPolicy.ToJsonString());

            ResumableUploader target = new ResumableUploader();
            HttpResult        result = target.UploadData(data, key, token, null);

            Assert.AreEqual((int)HttpCode.OK, result.Code);
        }