123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
-
- using System;
- using System.Collections.Generic;
- using Aliyun.OSS.Util;
- namespace Aliyun.OSS
- {
-
-
-
-
-
-
- public class ObjectMetadata
- {
- private readonly IDictionary<string, string> _userMetadata =
- new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
- private readonly IDictionary<string, object> _metadata =
- new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
-
-
-
- public const string Aes256ServerSideEncryption = "AES256";
-
-
-
-
-
-
-
-
-
-
- public IDictionary<string, string> UserMetadata
- {
- get { return _userMetadata; }
- }
-
-
-
- public DateTime LastModified
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.LastModified)
- ? (DateTime)_metadata[HttpHeaders.LastModified] : DateTime.MinValue;
- }
- internal set
- {
- _metadata[HttpHeaders.LastModified] = value;
- }
- }
-
-
-
- public DateTime ExpirationTime
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.Expires)
- ? DateUtils.ParseRfc822Date((string)_metadata[HttpHeaders.Expires]) : DateTime.MinValue;
- }
- set
- {
- _metadata[HttpHeaders.Expires] = DateUtils.FormatRfc822Date(value);
- }
- }
-
-
-
- public long ContentLength
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.ContentLength)
- ? (long)_metadata[HttpHeaders.ContentLength] : 0;
- }
- set
- {
- if (value > OssUtils.MaxFileSize)
- throw new ArgumentException("content length not allow to exceed 5GB.");
- _metadata[HttpHeaders.ContentLength] = value;
- }
- }
-
-
-
- public string ContentType
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.ContentType)
- ? _metadata[HttpHeaders.ContentType] as string : null;
- }
- set
- {
- if (!string.IsNullOrEmpty(value))
- {
- _metadata[HttpHeaders.ContentType] = value;
- }
- }
- }
-
-
-
- public string ContentEncoding
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.ContentEncoding)
- ? _metadata[HttpHeaders.ContentEncoding] as string : null;
- }
- set
- {
- if (value != null)
- {
- _metadata[HttpHeaders.ContentEncoding] = value;
- }
- }
- }
-
-
-
- public string CacheControl
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.CacheControl)
- ? _metadata[HttpHeaders.CacheControl] as string : null;
- }
- set
- {
- if (value != null)
- {
- _metadata[HttpHeaders.CacheControl] = value;
- }
- }
- }
-
-
-
- public string ContentDisposition
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.ContentDisposition)
- ? _metadata[HttpHeaders.ContentDisposition] as string : null;
- }
- set
- {
- if (value != null)
- {
- _metadata[HttpHeaders.ContentDisposition] = value;
- }
- }
- }
-
-
-
- public string ETag
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.ETag)
- ? _metadata[HttpHeaders.ETag] as string : null;
- }
- set
- {
- if (value != null)
- {
- _metadata[HttpHeaders.ETag] = value;
- }
- }
- }
-
-
-
- public string ContentMd5
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.ContentMd5)
- ? _metadata[HttpHeaders.ContentMd5] as string : null;
- }
- set
- {
- if (value != null)
- {
- _metadata[HttpHeaders.ContentMd5] = value;
- }
- }
- }
-
-
-
- public string ServerSideEncryption
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.ServerSideEncryption)
- ? _metadata[HttpHeaders.ServerSideEncryption] as string : null;
- }
- set
- {
- if (Aes256ServerSideEncryption != value)
- throw new ArgumentException("Unsupported server side encryption");
- _metadata[HttpHeaders.ServerSideEncryption] = value;
- }
- }
-
-
-
- public string ObjectType
- {
- get
- {
- return _metadata.ContainsKey(HttpHeaders.ObjectType)
- ? _metadata[HttpHeaders.ObjectType] as string : null;
- }
- }
-
-
-
- public ObjectMetadata()
- {
- ContentLength = -1L;
- }
-
-
-
-
-
- public void AddHeader(string key, object value)
- {
- _metadata.Add(key, value);
- }
-
-
-
-
- internal void Populate(IDictionary<string, string> requestHeaders)
- {
- foreach(var entry in _metadata)
- requestHeaders.Add(entry.Key, entry.Value.ToString());
-
- if (!requestHeaders.ContainsKey(HttpHeaders.ContentType))
- requestHeaders.Add(HttpHeaders.ContentType, HttpUtils.DefaultContentType);
- foreach(var entry in _userMetadata)
- requestHeaders.Add(OssHeaders.OssUserMetaPrefix + entry.Key, entry.Value);
- }
- }
- }
|