/*
* Copyright (C) Alibaba Cloud Computing
* All rights reserved.
*
* 版权所有 (C)阿里云计算有限公司
*/
using System;
using System.Collections.Generic;
using Aliyun.OSS.Util;
namespace Aliyun.OSS
{
///
/// 指定生成URL预签名的请求参数。
///
public class GeneratePresignedUriRequest
{
private SignHttpMethod _method;
private IDictionary _userMetadata = new Dictionary();
private IDictionary _queryParams = new Dictionary();
private ResponseHeaderOverrides _responseHeader = new ResponseHeaderOverrides();
///
/// 获取或者设置HttpMethod。
///
public SignHttpMethod Method
{
get { return _method; }
set
{
if (_method != SignHttpMethod.Get && _method != SignHttpMethod.Put)
throw new ArgumentException("Only supports Get & Put method.");
_method = value;
}
}
///
/// 获取或者设置Object所在Bucket的名称。
///
public string BucketName { get; set; }
///
/// 获取或者设置Object的名称。
///
public string Key { get; set; }
///
/// 获取或设置签名URL对应的文件类型。
///
public string ContentType { get; set; }
///
/// 获取或设置签名URL对应的文件MD5。
///
public string ContentMd5 { get; set; }
///
/// 获取或者设置过期时间。
///
public DateTime Expiration { get; set; }
///
/// 获取或者设置要重载的返回请求头。
///
public ResponseHeaderOverrides ResponseHeaders
{
get { return _responseHeader; }
set
{
if (value == null)
throw new ArgumentException("ResponseHeaderOverrides should not be null");
_responseHeader = value;
}
}
///
/// 获取或者设置用户自定义的元数据,表示以x-oss-meta-为前缀的请求头。
///
public IDictionary UserMetadata
{
get { return _userMetadata; }
set
{
if (value == null)
throw new ArgumentException("UserMetadata should not be null");
_userMetadata = value;
}
}
///
/// 获取或者设置用户请求参数。
///
public IDictionary QueryParams
{
get { return _queryParams; }
set
{
if (value == null)
throw new ArgumentException("QueryParams should not be null");
_queryParams = value;
}
}
///
/// 添加用户Meta项
///
/// meta的名称
/// metal的值
public void AddUserMetadata(string metaItem, string value)
{
_userMetadata.Add(metaItem, value);
}
///
/// 添加用户参数
///
/// 参数名称
/// 参数值
public void AddQueryParam(string param, string value)
{
_queryParams.Add(param, value);
}
///
/// 构造一个新的实例。
///
/// 所在的名称
/// 的
public GeneratePresignedUriRequest(string bucketName, string key)
: this(bucketName, key, SignHttpMethod.Get)
{
}
///
/// 构造一个新的实例。
///
/// 所在的名称。
/// 的
/// http传输方式
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);
}
}
}