本文整理汇总了C#中BlobProperties类的典型用法代码示例。如果您正苦于以下问题:C# BlobProperties类的具体用法?C# BlobProperties怎么用?C# BlobProperties使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlobProperties类属于命名空间,在下文中一共展示了BlobProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Put
/// <summary>
/// Constructs a web request to create a new block blob or page blob, or to update the content
/// of an existing block blob.
/// </summary>
/// <param name="uri">The absolute URI to the blob.</param>
/// <param name="timeout">The server timeout interval.</param>
/// <param name="properties">The properties to set for the blob.</param>
/// <param name="blobType">The type of the blob.</param>
/// <param name="pageBlobSize">For a page blob, the size of the blob. This parameter is ignored
/// for block blobs.</param>
/// <param name="accessCondition">The access condition to apply to the request.</param>
/// <returns>A web request to use to perform the operation.</returns>
public static HttpRequestMessage Put(Uri uri, int? timeout, BlobProperties properties, BlobType blobType, long pageBlobSize, AccessCondition accessCondition, HttpContent content, OperationContext operationContext)
{
if (blobType == BlobType.Unspecified)
{
throw new InvalidOperationException(SR.UndefinedBlobType);
}
HttpRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Put, uri, timeout, null /* builder */, content, operationContext);
if (properties.CacheControl != null)
{
request.Headers.CacheControl = CacheControlHeaderValue.Parse(properties.CacheControl);
}
if (content != null)
{
if (properties.ContentType != null)
{
content.Headers.ContentType = MediaTypeHeaderValue.Parse(properties.ContentType);
}
if (properties.ContentMD5 != null)
{
content.Headers.ContentMD5 = Convert.FromBase64String(properties.ContentMD5);
}
if (properties.ContentLanguage != null)
{
content.Headers.ContentLanguage.Add(properties.ContentLanguage);
}
if (properties.ContentEncoding != null)
{
content.Headers.ContentEncoding.Add(properties.ContentEncoding);
}
if (properties.ContentDisposition != null)
{
content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse(properties.ContentDisposition);
}
}
if (blobType == BlobType.PageBlob)
{
request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.PageBlob);
request.Headers.Add(Constants.HeaderConstants.BlobContentLengthHeader, pageBlobSize.ToString(NumberFormatInfo.InvariantInfo));
properties.Length = pageBlobSize;
}
else if (blobType == BlobType.BlockBlob)
{
request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.BlockBlob);
}
else
{
request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.AppendBlob);
}
request.ApplyAccessCondition(accessCondition);
return request;
}
示例2: Put
/// <summary>
/// Constructs a web request to create a new block blob or page blob, or to update the content
/// of an existing block blob.
/// </summary>
/// <param name="uri">The absolute URI to the blob.</param>
/// <param name="timeout">The server timeout interval.</param>
/// <param name="properties">The properties to set for the blob.</param>
/// <param name="blobType">The type of the blob.</param>
/// <param name="leaseId">The lease ID, if the blob has an active lease.</param>
/// <param name="pageBlobSize">For a page blob, the size of the blob. This parameter is ignored
/// for block blobs.</param>
/// <returns>A web request to use to perform the operation.</returns>
public static HttpWebRequest Put(Uri uri, int timeout, BlobProperties properties, BlobType blobType, string leaseId, long pageBlobSize)
{
if (blobType == BlobType.Unspecified)
{
throw new InvalidOperationException(SR.UndefinedBlobType);
}
HttpWebRequest request = CreateWebRequest(uri, timeout, null);
request.Method = "PUT";
if (properties.CacheControl != null)
{
request.Headers.Add(HttpRequestHeader.CacheControl, properties.CacheControl);
}
if (properties.ContentType != null)
{
// Setting it using Headers is an exception
request.ContentType = properties.ContentType;
}
if (properties.ContentMD5 != null)
{
request.Headers.Add(HttpRequestHeader.ContentMd5, properties.ContentMD5);
}
if (properties.ContentLanguage != null)
{
request.Headers.Add(HttpRequestHeader.ContentLanguage, properties.ContentLanguage);
}
if (properties.ContentEncoding != null)
{
request.Headers.Add(HttpRequestHeader.ContentEncoding, properties.ContentEncoding);
}
if (blobType == BlobType.PageBlob)
{
request.ContentLength = 0;
request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.PageBlob);
request.Headers.Add(Constants.HeaderConstants.Size, pageBlobSize.ToString(NumberFormatInfo.InvariantInfo));
properties.Length = pageBlobSize;
}
else
{
request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.BlockBlob);
}
Request.AddLeaseId(request, leaseId);
return request;
}
示例3: PutBlobRequest
public static HttpWebRequest PutBlobRequest(BlobContext context, string containerName, string blobName,
BlobProperties properties, BlobType blobType, byte[] content, long pageBlobSize, AccessCondition accessCondition)
{
bool valid = BlobTests.ContainerNameValidator(containerName) &&
BlobTests.BlobNameValidator(blobName) &&
BlobTests.PutPropertiesValidator(properties) &&
BlobTestUtils.ContentValidator(content);
bool fatal = !BlobTests.PutPropertiesValidator(properties);
Uri uri = BlobTests.ConstructPutUri(context.Address, containerName, blobName);
HttpWebRequest request = null;
OperationContext opContext = new OperationContext();
try
{
request = BlobHttpWebRequestFactory.Put(uri, context.Timeout, properties, blobType, pageBlobSize, accessCondition, opContext);
if (fatal)
{
Assert.Fail();
}
}
catch (InvalidOperationException)
{
if (valid)
{
Assert.Fail();
}
}
if (valid)
{
Assert.IsNotNull(request);
Assert.IsNotNull(request.Method);
Assert.AreEqual("PUT", request.Method);
BlobTestUtils.VersionHeader(request, false);
BlobTestUtils.ContentTypeHeader(request, null);
BlobTestUtils.ContentDispositionHeader(request, properties.ContentDisposition);
BlobTestUtils.ContentEncodingHeader(request, properties.ContentEncoding);
BlobTestUtils.ContentLanguageHeader(request, null);
BlobTestUtils.ContentMd5Header(request, null);
BlobTestUtils.CacheControlHeader(request, null);
BlobTestUtils.BlobTypeHeader(request, properties.BlobType);
BlobTestUtils.BlobSizeHeader(request, (properties.BlobType == BlobType.PageBlob) ? properties.Length : (long?)null);
}
return request;
}
示例4: GetProperties
/// <summary>
/// Gets the blob's properties from the response.
/// </summary>
/// <param name="response">The web response.</param>
/// <returns>The blob's properties.</returns>
public static BlobProperties GetProperties(HttpWebResponse response)
{
BlobProperties properties = new BlobProperties();
properties.LastModified = response.LastModified.ToUniversalTime();
properties.ContentEncoding = response.Headers[HttpResponseHeader.ContentEncoding];
properties.ContentLanguage = response.Headers[HttpResponseHeader.ContentLanguage];
properties.ContentMD5 = response.Headers[HttpResponseHeader.ContentMd5];
properties.ContentType = response.Headers[HttpResponseHeader.ContentType];
properties.CacheControl = response.Headers[HttpResponseHeader.CacheControl];
properties.ETag = HttpResponseParsers.GetETag(response);
string blobType = response.Headers[Constants.HeaderConstants.BlobType];
// Get blob type
if (!string.IsNullOrEmpty(blobType))
{
properties.BlobType = (BlobType)Enum.Parse(typeof(BlobType), blobType, true);
}
// Get lease properties
properties.LeaseStatus = GetLeaseStatus(response);
properties.LeaseState = GetLeaseState(response);
properties.LeaseDuration = GetLeaseDuration(response);
// Get the content length. Prioritize range and x-ms over content length for the special cases.
string rangeHeader = response.Headers[HttpResponseHeader.ContentRange];
string contentLengthHeader = response.Headers[Constants.HeaderConstants.ContentLengthHeader];
if (!string.IsNullOrEmpty(rangeHeader))
{
properties.Length = long.Parse(rangeHeader.Split('/')[1]);
}
else if (!string.IsNullOrEmpty(contentLengthHeader))
{
properties.Length = long.Parse(contentLengthHeader);
}
else
{
properties.Length = response.ContentLength;
}
return properties;
}
示例5: Test_Blob_ContentDisposition_Updated_Async
public async void Test_Blob_ContentDisposition_Updated_Async()
{
var container = GetRandomContainerName();
var blobName = GenerateRandomName();
var filename = "testname.jpg";
var contentType = "image/jpg";
var newContentType = "image/png";
var data = GenerateRandomBlobStream();
await CreateNewObjectAsync(container, blobName, data, false, contentType);
var newProps = new BlobProperties
{
ContentType = newContentType,
Security = BlobSecurity.Public,
}.WithContentDispositionFilename(filename);
await _provider.UpdateBlobPropertiesAsync(container, blobName, newProps);
var meta = await _client.GetObjectMetadataAsync(Bucket, container + "/" + blobName);
Assert.Equal(newProps.ContentDisposition, meta.Headers.ContentDisposition);
}
示例6: Put
/// <summary>
/// Constructs a web request to create a new block blob or page blob, or to update the content
/// of an existing block blob.
/// </summary>
/// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the blob.</param>
/// <param name="timeout">An integer specifying the server timeout interval.</param>
/// <param name="properties">A <see cref="BlobProperties"/> object.</param>
/// <param name="blobType">A <see cref="BlobType"/> enumeration value.</param>
/// <param name="pageBlobSize">For a page blob, the size of the blob. This parameter is ignored
/// for block blobs.</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed.</param>
/// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
/// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns>
public static HttpWebRequest Put(Uri uri, int? timeout, BlobProperties properties, BlobType blobType, long pageBlobSize, AccessCondition accessCondition, bool useVersionHeader, OperationContext operationContext)
{
CommonUtility.AssertNotNull("properties", properties);
if (blobType == BlobType.Unspecified)
{
throw new InvalidOperationException(SR.UndefinedBlobType);
}
HttpWebRequest request = HttpWebRequestFactory.CreateWebRequest(WebRequestMethods.Http.Put, uri, timeout, null /* builder */, useVersionHeader, operationContext);
if (properties.CacheControl != null)
{
request.Headers[HttpRequestHeader.CacheControl] = properties.CacheControl;
}
if (properties.ContentType != null)
{
// Setting it using Headers is an exception
request.ContentType = properties.ContentType;
}
if (properties.ContentMD5 != null)
{
request.Headers[HttpRequestHeader.ContentMd5] = properties.ContentMD5;
}
if (properties.ContentLanguage != null)
{
request.Headers[HttpRequestHeader.ContentLanguage] = properties.ContentLanguage;
}
if (properties.ContentEncoding != null)
{
request.Headers[HttpRequestHeader.ContentEncoding] = properties.ContentEncoding;
}
if (properties.ContentDisposition != null)
{
request.Headers[Constants.HeaderConstants.BlobContentDispositionRequestHeader] = properties.ContentDisposition;
}
if (blobType == BlobType.PageBlob)
{
request.Headers[Constants.HeaderConstants.BlobType] = Constants.HeaderConstants.PageBlob;
request.Headers[Constants.HeaderConstants.BlobContentLengthHeader] = pageBlobSize.ToString(NumberFormatInfo.InvariantInfo);
properties.Length = pageBlobSize;
}
else if (blobType == BlobType.BlockBlob)
{
request.Headers[Constants.HeaderConstants.BlobType] = Constants.HeaderConstants.BlockBlob;
}
else
{
request.Headers[Constants.HeaderConstants.BlobType] = Constants.HeaderConstants.AppendBlob;
}
request.ApplyAccessCondition(accessCondition);
return request;
}
示例7: PutPropertiesValidator
public static bool PutPropertiesValidator(BlobProperties properties)
{
if (properties.BlobType == BlobType.Unspecified)
{
return false;
}
if ((properties.BlobType == BlobType.PageBlob) &&
(properties.Length % 512 != 0) &&
(properties.Length > 0))
{
return false;
}
return true;
}
示例8: PutBlockList
/// <summary>
/// Constructs a web request to create or update a blob by committing a block list.
/// </summary>
/// <param name="uri">The absolute URI to the blob.</param>
/// <param name="timeout">The server timeout interval.</param>
/// <param name="properties">The properties to set for the blob.</param>
/// <param name="accessCondition">The access condition to apply to the request.</param>
/// <returns>A web request for performing the operation.</returns>
public static StorageRequestMessage PutBlockList(Uri uri, int? timeout, BlobProperties properties, AccessCondition accessCondition, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
{
UriQueryBuilder builder = new UriQueryBuilder();
builder.Add(Constants.QueryConstants.Component, "blocklist");
StorageRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Put, uri, timeout, builder, content, operationContext, canonicalizer, credentials);
if (properties != null)
{
request.AddOptionalHeader(Constants.HeaderConstants.BlobCacheControlHeader, properties.CacheControl);
request.AddOptionalHeader(Constants.HeaderConstants.BlobContentTypeHeader, properties.ContentType);
request.AddOptionalHeader(Constants.HeaderConstants.BlobContentMD5Header, properties.ContentMD5);
request.AddOptionalHeader(Constants.HeaderConstants.BlobContentLanguageHeader, properties.ContentLanguage);
request.AddOptionalHeader(Constants.HeaderConstants.BlobContentEncodingHeader, properties.ContentEncoding);
request.AddOptionalHeader(Constants.HeaderConstants.BlobContentDispositionRequestHeader, properties.ContentDisposition);
}
request.ApplyAccessCondition(accessCondition);
return request;
}
示例9: SetProperties
/// <summary>
/// Constructs a web request to set system properties for a blob.
/// </summary>
/// <param name="uri">The absolute URI to the blob.</param>
/// <param name="timeout">The server timeout interval.</param>
/// <param name="properties">The blob's properties.</param>
/// <param name="leaseId">The lease ID, if the blob has an active lease.</param>
/// <param name="newBlobSize">The new blob size, if the blob is a page blob. Set this parameter to <c>null</c> to keep the existing blob size.</param>
/// <returns>A web request to use to perform the operation.</returns>
public static HttpWebRequest SetProperties(Uri uri, int timeout, BlobProperties properties, string leaseId, long? newBlobSize)
{
UriQueryBuilder builder = new UriQueryBuilder();
builder.Add(Constants.QueryConstants.Component, "properties");
HttpWebRequest request = CreateWebRequest(uri, timeout, builder);
request.ContentLength = 0;
request.Method = "PUT";
Request.AddLeaseId(request, leaseId);
if (newBlobSize.HasValue)
{
request.Headers.Add(Constants.HeaderConstants.Size, newBlobSize.Value.ToString(NumberFormatInfo.InvariantInfo));
properties.Length = newBlobSize.Value;
}
Request.AddOptionalHeader(request, Constants.HeaderConstants.CacheControlHeader, properties.CacheControl);
Request.AddOptionalHeader(request, Constants.HeaderConstants.ContentEncodingHeader, properties.ContentEncoding);
Request.AddOptionalHeader(request, Constants.HeaderConstants.ContentLanguageHeader, properties.ContentLanguage);
Request.AddOptionalHeader(request, Constants.HeaderConstants.BlobContentMD5Header, properties.ContentMD5);
Request.AddOptionalHeader(request, Constants.HeaderConstants.ContentTypeHeader, properties.ContentType);
return request;
}
示例10: GetProperties
/// <summary>
/// Gets the blob's properties from the response.
/// </summary>
/// <param name="response">The web response.</param>
/// <returns>The blob's properties.</returns>
public static BlobProperties GetProperties(HttpWebResponse response)
{
CommonUtility.AssertNotNull("response", response);
BlobProperties properties = new BlobProperties();
properties.ETag = HttpResponseParsers.GetETag(response);
#if WINDOWS_PHONE
properties.LastModified = HttpResponseParsers.GetLastModified(response);
properties.ContentLanguage = response.Headers[Constants.HeaderConstants.ContentLanguageHeader];
#else
properties.LastModified = response.LastModified.ToUniversalTime();
properties.ContentLanguage = response.Headers[HttpResponseHeader.ContentLanguage];
#endif
properties.ContentDisposition = response.Headers[Constants.HeaderConstants.ContentDispositionResponseHeader];
properties.ContentEncoding = response.Headers[HttpResponseHeader.ContentEncoding];
properties.ContentMD5 = response.Headers[HttpResponseHeader.ContentMd5];
properties.ContentType = response.Headers[HttpResponseHeader.ContentType];
properties.CacheControl = response.Headers[HttpResponseHeader.CacheControl];
// Get blob type
string blobType = response.Headers[Constants.HeaderConstants.BlobType];
if (!string.IsNullOrEmpty(blobType))
{
properties.BlobType = (BlobType)Enum.Parse(typeof(BlobType), blobType, true);
}
// Get lease properties
properties.LeaseStatus = GetLeaseStatus(response);
properties.LeaseState = GetLeaseState(response);
properties.LeaseDuration = GetLeaseDuration(response);
// Get the content length. Prioritize range and x-ms over content length for the special cases.
string rangeHeader = response.Headers[HttpResponseHeader.ContentRange];
string contentLengthHeader = response.Headers[Constants.HeaderConstants.ContentLengthHeader];
string blobContentLengthHeader = response.Headers[Constants.HeaderConstants.BlobContentLengthHeader];
if (!string.IsNullOrEmpty(rangeHeader))
{
properties.Length = long.Parse(rangeHeader.Split('/')[1], CultureInfo.InvariantCulture);
}
else if (!string.IsNullOrEmpty(blobContentLengthHeader))
{
properties.Length = long.Parse(blobContentLengthHeader, CultureInfo.InvariantCulture);
}
else if (!string.IsNullOrEmpty(contentLengthHeader))
{
// On Windows Phone, ContentLength property is not always same as Content-Length header,
// so we try to parse the header first.
properties.Length = long.Parse(contentLengthHeader, CultureInfo.InvariantCulture);
}
else
{
properties.Length = response.ContentLength;
}
// Get sequence number
string sequenceNumber = response.Headers[Constants.HeaderConstants.BlobSequenceNumber];
if (!string.IsNullOrEmpty(sequenceNumber))
{
properties.PageBlobSequenceNumber = long.Parse(sequenceNumber, CultureInfo.InvariantCulture);
}
return properties;
}
示例11: GetBlobScenarioTest
public void GetBlobScenarioTest(string containerName, string blobName, BlobProperties properties, string leaseId,
byte[] content, HttpStatusCode? expectedError)
{
HttpWebRequest request = BlobTests.GetBlobRequest(BlobContext, containerName, blobName, AccessCondition.GenerateLeaseCondition(leaseId));
Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
if (BlobContext.Credentials != null)
{
BlobTests.SignRequest(request, BlobContext);
}
HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext);
try
{
BlobTests.GetBlobResponse(response, BlobContext, properties, content, expectedError);
}
finally
{
response.Close();
}
}
示例12: PutBlobScenarioTest
public void PutBlobScenarioTest(string containerName, string blobName, BlobProperties properties, BlobType blobType, byte[] content, HttpStatusCode? expectedError)
{
HttpWebRequest request = BlobTests.PutBlobRequest(BlobContext, containerName, blobName, properties, blobType, content, content.Length, null);
Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
request.ContentLength = content.Length;
if (BlobContext.Credentials != null)
{
BlobTests.SignRequest(request, BlobContext);
}
BlobTestUtils.SetRequest(request, BlobContext, content);
HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext);
try
{
BlobTests.PutBlobResponse(response, BlobContext, expectedError);
}
finally
{
response.Close();
}
}
示例13: BlobProtocolPutPageBlobCloudAnonAsync
public void BlobProtocolPutPageBlobCloudAnonAsync()
{
BlobProperties properties = new BlobProperties() { BlobType = BlobType.PageBlob };
cloudAnonAsync.PutBlobScenarioTest(cloudSetup.ContainerName, Guid.NewGuid().ToString(),
properties, BlobType.PageBlob, new byte[0], HttpStatusCode.NotFound);
}
示例14: BlobProtocolPutBlockBlobCloudAnonAsync
public void BlobProtocolPutBlockBlobCloudAnonAsync()
{
byte[] content = new byte[6000];
random.NextBytes(content);
BlobProperties properties = new BlobProperties() { BlobType = BlobType.BlockBlob };
cloudAnonAsync.PutBlobScenarioTest(cloudSetup.ContainerName, Guid.NewGuid().ToString(),
properties, BlobType.BlockBlob, content, HttpStatusCode.NotFound);
}
示例15: PutBlockList
/// <summary>
/// Constructs a web request to create or update a blob by committing a block list.
/// </summary>
/// <param name="uri">The absolute URI to the blob.</param>
/// <param name="timeout">The server timeout interval.</param>
/// <param name="properties">The properties to set for the blob.</param>
/// <param name="accessCondition">The access condition to apply to the request.</param>
/// <returns>A web request for performing the operation.</returns>
public static HttpRequestMessage PutBlockList(Uri uri, int? timeout, BlobProperties properties, AccessCondition accessCondition, HttpContent content, OperationContext operationContext)
{
UriQueryBuilder builder = new UriQueryBuilder();
builder.Add(Constants.QueryConstants.Component, "blocklist");
HttpRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Put, uri, timeout, builder, content, operationContext);
request.AddOptionalHeader(Constants.HeaderConstants.CacheControlHeader, properties.CacheControl);
request.AddOptionalHeader(Constants.HeaderConstants.ContentTypeHeader, properties.ContentType);
request.AddOptionalHeader(Constants.HeaderConstants.BlobContentMD5Header, properties.ContentMD5);
request.AddOptionalHeader(Constants.HeaderConstants.BlobContentLanguageHeader, properties.ContentLanguage);
request.AddOptionalHeader(Constants.HeaderConstants.ContentEncodingHeader, properties.ContentEncoding);
request.ApplyAccessCondition(accessCondition);
return request;
}