指定生成URL预签名的请求参数。
        public void GenerateUriWithProcessTest()
        {
            try
            {
                // put example image
                _ossClient.PutObject(_bucketName, _keyName, _localImageFile);

                // generate uri
                var req = new GeneratePresignedUriRequest(_bucketName, _keyName, SignHttpMethod.Get)
                {
                    Expiration = DateTime.Now.AddHours(1),
                    Process = _process
                };
                var uri = _ossClient.GeneratePresignedUri(req);

                // get processed image
                OssObject ossObject = _ossClient.GetObject(uri);

                // put processed image
                Stream seekableStream = ConvertStreamToSeekable(ossObject.Content);
                _ossClient.PutObject(_bucketName, _processedKey, seekableStream);

                // get info of processed image
                var imgInfo = GetOssImageObjectInfo(_bucketName, _processedKey);

                // check processed result
                Assert.AreEqual(imgInfo, _imageInfo);
            }
            finally
            {
                _ossClient.DeleteObject(_bucketName, _keyName);
                _ossClient.DeleteObject(_bucketName, _processedKey);
            }
        }
        public void GetPreSignedUriWithUserMetaPositiveTest()
        {
            HttpWebRequest req = null;
            HttpWebResponse res = null;

            var now = DateTime.Now;
            //set expiration time to 5 seconds later
            var expireDate = now.AddSeconds(5);
            var gpuRequest = new GeneratePresignedUriRequest(_bucketName, _objectKey);
            gpuRequest.Expiration = expireDate;
            gpuRequest.UserMetadata.Add("name1", "vaue1");
            gpuRequest.UserMetadata.Add("name2", "vaue2");
            var uri = _ossClient.GeneratePresignedUri(gpuRequest);
            Console.WriteLine(uri);
            try
            {
                req = WebRequest.Create(uri) as HttpWebRequest;
                req.Method = "GET";
                req.Headers.Add("x-oss-meta-name1", "vaue1");
                req.Headers.Add("x-oss-meta-name2", "vaue2");
                res = req.GetResponse() as HttpWebResponse;
                Assert.AreEqual(HttpStatusCode.OK, res.StatusCode, "response status code is not expected.");
                using (var stream = res.GetResponseStream())
                {
                    var actualETag = FileUtils.ComputeContentMd5(stream);
                    Assert.AreEqual(_objectETag.ToLowerInvariant(), actualETag.ToLowerInvariant());
                }
            }
            catch (WebException)
            {
                //TODO:
            }
            finally
            {
                if (req != null) req.Abort();
                if (res != null) res.Close();
            }
        }
        public void GetPreSignedUriWithResponseHeaderPositiveTest()
        {
            HttpWebRequest req = null;
            HttpWebResponse res = null;

            var now = DateTime.Now;
            //set expiration time to 5 seconds later
            var expireDate = now.AddSeconds(5);
            var gpuRequest = new GeneratePresignedUriRequest(_bucketName, _objectKey)
            {
                Expiration = expireDate,
                ResponseHeaders =
                {
                    CacheControl = "No-cache",
                    ContentType = "application/zip",
                    ContentDisposition = "myDownload.zip"
                }
            };
            var uri = _ossClient.GeneratePresignedUri(gpuRequest);
            Console.WriteLine(uri);
            try
            {
                req = WebRequest.Create(uri) as HttpWebRequest;
                req.Method = "GET";
                res = req.GetResponse() as HttpWebResponse;
                Assert.AreEqual(HttpStatusCode.OK, res.StatusCode, "response status code is not expected.");
                using (var stream = res.GetResponseStream())
                {
                    var actualETag = FileUtils.ComputeContentMd5(stream);
                    Assert.AreEqual(_objectETag.ToLowerInvariant(), actualETag.ToLowerInvariant());
                }
            }
            catch (WebException)
            {
                //TODO:
            }
            finally
            {
                if (req != null) req.Abort();
                if (res != null) res.Close();
            }
        }
        public void GetPreSignedUriWithContentTypeAndMd5NegativeTest()
        {
            HttpWebRequest req = null;
            HttpWebResponse res = null;

            var now = DateTime.Now;
            //set expiration time to 5 seconds later
            var expireDate = now.AddSeconds(5);
            var gpuRequest = new GeneratePresignedUriRequest(_bucketName, _objectKey);
            gpuRequest.Expiration = expireDate;
            //do not set content type
            //gpuRequest.ContentType = "application/zip";
            gpuRequest.ContentMd5 = _objectETag;
            var uri = _ossClient.GeneratePresignedUri(gpuRequest);
            Console.WriteLine(uri);
            try
            {
                req = WebRequest.Create(uri) as HttpWebRequest;
                req.Method = "GET";
                req.ContentType = "application/zip";
                req.Headers.Add(HttpRequestHeader.ContentMd5, _objectETag);
                res = req.GetResponse() as HttpWebResponse;
                Assert.Fail("response fail for expired URI");
            }
            catch (WebException e)
            {
                Assert.IsTrue(e.Message.Contains("403"),
                    string.Format("Unexpected exception: {0}", e.Message));
            }
            finally
            {
                if (req != null) req.Abort();
                if (res != null) res.Close();
            }
        }
 public static Task <Uri> GeneratePresignedUriAsync(this IOss client, GeneratePresignedUriRequest generatePresignedUriRequest)
 {
     return(Task.Factory.StartNew(() => client.GeneratePresignedUri(generatePresignedUriRequest)));
 }