示例#1
0
        /// <summary>
        /// 上传指定文件到UCloud对象存储。
        /// </summary>
        /// <param name="file">待上传的文件</param>
        /// <param name="suffix">文件在云空间里的后缀</param>
        /// <exception cref="Exception"/>
        public Task Upload(string file, string suffix)
        {
            if (bucketDomain.StartsWith(bucket) == false)
            {
                throw new Exception(string.Format("Bucket\"{0}\"的BucketDomain不是\"{1}\"!", bucket, bucketDomain));
            }

            UFile u = new UFile(publicKey, privateKey);

            u.FileUrl = "http://{0}" + bucketDomain.Substring(bucket.Length);
            var res = u.PutFile(file, path + suffix, bucket);

            if (res.RetCode != 0)
            {
                throw new Exception(string.Format("上传失败。\n\tXSessionId:{0}\n\t错误信息:{1}", res.XSessionId, res.ErrMsg));
            }

            return(Task.CompletedTask);
        }
示例#2
0
        public void PutFileTest()
        {
            var response = ufile.PutFile(filePath);

            Assert.AreEqual(response.RetCode, 0);
        }