Ejemplo n.º 1
0
        /// <inheritdoc/>
        public Uri GeneratePresignedUri(string bucketName, string key, DateTime expiration,
                                        SignHttpMethod method)
        {
            var request = new GeneratePresignedUriRequest(bucketName, key, method)
            {
                Expiration = expiration
            };

            return(GeneratePresignedUri(request));
        }
        /// <summary>
        /// 构造一个新的<see cref="GeneratePresignedUriRequest" />实例。
        /// </summary>
        /// <param name="bucketName"><see cref="OssObject" />所在<see cref="Bucket" />的名称。</param>
        /// <param name="key"><see cref="OssObject" />的<see cref="P:OssObject.Key" /></param>
        /// <param name="httpMethod">http传输方式</param>
        public GeneratePresignedUriRequest(string bucketName, string key, SignHttpMethod httpMethod)
        {
            OssUtils.CheckBucketName(bucketName);
            OssUtils.CheckObjectKey(key);

            BucketName = bucketName;
            Key = key;
            Method = httpMethod;
            // Default expiration(15 minutes from now) for signed url.
            Expiration = DateTime.Now.AddMinutes(15);
        }
        public GeneratePresignedUriRequest(string bucketName, string key, SignHttpMethod httpMethod)
        {
            OssUtils.CheckBucketName(bucketName);
            OssUtils.CheckObjectKey(key);

            BucketName = bucketName;
            Key        = key;
            Method     = httpMethod;
            // Default expiration(15 minutes from now) for signed url.
            Expiration = DateTime.Now.AddMinutes(15);
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public Uri GeneratePresignedUri(string bucketName, string key, SignHttpMethod method)
        {
            var request = new GeneratePresignedUriRequest(bucketName, key, method);

            return(GeneratePresignedUri(request));
        }
Ejemplo n.º 5
0
        public Uri GeneratePresignedUri(string bucketName, string key, int expiration_s, SignHttpMethod method)
        {
            if (expiration_s == 0)
            {
                expiration_s = 3600;
            }
            var req = new GeneratePresignedUriRequest(bucketName, key, method);

            req.Expiration = DateTime.Now.AddSeconds(expiration_s);
            //req.ContentType = "text/html";
            //req.ContentMd5 = etag;
            //req.ResponseHeaders.CacheControl = "No-Cache";
            //req.ResponseHeaders.ContentEncoding = "utf-8";
            //req.ResponseHeaders.ContentType = "text/html";
            var client = GetClient();
            var uri    = client.GeneratePresignedUri(req);

            return(uri);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates the BLOB credential.
        /// </summary>
        /// <param name="containerName">Name of the container.</param>
        /// <param name="blobIdentifier">The BLOB identifier.</param>
        /// <param name="expireOffsetInMinute">The expire offset in minute.</param>
        /// <param name="method">The method.</param>
        /// <param name="putUserMeta">The put user meta.</param>
        /// <returns></returns>
        private BinaryStorageActionCredential CreateBlobCredential(string containerName,
                                                                   string blobIdentifier, int expireOffsetInMinute, SignHttpMethod method, Action <GeneratePresignedUriRequest> putUserMeta = null)
        {
            var expiredStamp = DateTime.UtcNow.AddMinutes(expireOffsetInMinute);
            GeneratePresignedUriRequest presignRequest = new GeneratePresignedUriRequest(containerName, blobIdentifier);

            presignRequest.Expiration = expiredStamp;
            presignRequest.Method     = method;

            putUserMeta?.Invoke(presignRequest);

            return(new BinaryStorageActionCredential
            {
                Container = containerName,
                Identifier = blobIdentifier,
                CredentialExpiredStamp = expiredStamp,
                CredentialUri = client.GeneratePresignedUri(presignRequest).ToString()
            });
        }
 public static Task <Uri> GeneratePresignedUriAsync(this IOss client, string bucketName, string key, DateTime expiration, SignHttpMethod method)
 {
     return(Task.Factory.StartNew(() => client.GeneratePresignedUri(bucketName, key, expiration, method)));
 }