/// <summary> /// Constructs a web request to get the blob's content, properties, and metadata. /// </summary> /// <param name="uri">The absolute URI to the blob.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="snapshot">The snapshot version, if the blob is a snapshot.</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 Get(Uri uri, int?timeout, DateTimeOffset?snapshot, AccessCondition accessCondition, HttpContent content, OperationContext operationContext) { UriQueryBuilder builder = new UriQueryBuilder(); if (snapshot.HasValue) { builder.Add("snapshot", BlobRequest.ConvertDateTimeToSnapshotString(snapshot.Value)); } HttpRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Get, uri, timeout, builder, content, operationContext); request.ApplyAccessCondition(accessCondition); return(request); }
public async Task PutBlockListScenarioTest(string containerName, string blobName, List <PutBlockListItem> blocks, BlobProperties blobProperties, string leaseId, HttpStatusCode?expectedError) { HttpRequestMessage request = BlobTests.PutBlockListRequest(BlobContext, containerName, blobName, blobProperties, AccessCondition.GenerateLeaseCondition(leaseId)); Assert.IsTrue(request != null, "Failed to create HttpRequestMessage"); byte[] content; using (MemoryStream stream = new MemoryStream()) { BlobRequest.WriteBlockListBody(blocks, stream); stream.Seek(0, SeekOrigin.Begin); content = new byte[stream.Length]; stream.Read(content, 0, content.Length); } //HttpRequestHandler.SetContentLength(request, content.Length); request.Content = new ByteArrayContent(content); using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext)) { BlobTests.PutBlockListResponse(response, BlobContext, expectedError); } }
private IListBlobEntry ParseBlobEntry(Uri baseUri) { BlobAttributes blob = new BlobAttributes(); string name = null; // copy blob attribute strings string copyId = null; string copyStatus = null; string copyCompletionTime = null; string copyProgress = null; string copySource = null; string copyStatusDescription = null; this.reader.ReadStartElement(); while (this.reader.IsStartElement()) { if (this.reader.IsEmptyElement) { this.reader.Skip(); } else { switch (this.reader.Name) { case Constants.NameElement: name = reader.ReadElementContentAsString(); break; case Constants.SnapshotElement: blob.SnapshotTime = reader.ReadElementContentAsString().ToUTCTime(); break; case Constants.PropertiesElement: this.reader.ReadStartElement(); while (this.reader.IsStartElement()) { if (this.reader.IsEmptyElement) { this.reader.Skip(); } else { switch (this.reader.Name) { case Constants.LastModifiedElement: blob.Properties.LastModified = reader.ReadElementContentAsString().ToUTCTime(); break; case Constants.EtagElement: blob.Properties.ETag = string.Format(CultureInfo.InvariantCulture, "\"{0}\"", reader.ReadElementContentAsString()); break; case Constants.ContentLengthElement: blob.Properties.Length = reader.ReadElementContentAsLong(); break; case Constants.CacheControlElement: blob.Properties.CacheControl = reader.ReadElementContentAsString(); break; case Constants.ContentTypeElement: blob.Properties.ContentType = reader.ReadElementContentAsString(); break; case Constants.HeaderConstants.ContentDispositionResponseHeader: blob.Properties.ContentDisposition = reader.ReadElementContentAsString(); break; case Constants.ContentEncodingElement: blob.Properties.ContentEncoding = reader.ReadElementContentAsString(); break; case Constants.ContentLanguageElement: blob.Properties.ContentLanguage = reader.ReadElementContentAsString(); break; case Constants.ContentMD5Element: blob.Properties.ContentMD5 = reader.ReadElementContentAsString(); break; case Constants.BlobTypeElement: string blobTypeString = reader.ReadElementContentAsString(); switch (blobTypeString) { case Constants.BlockBlobValue: blob.Properties.BlobType = BlobType.BlockBlob; break; case Constants.PageBlobValue: blob.Properties.BlobType = BlobType.PageBlob; break; } break; case Constants.LeaseStatusElement: blob.Properties.LeaseStatus = BlobHttpResponseParsers.GetLeaseStatus(reader.ReadElementContentAsString()); break; case Constants.LeaseStateElement: blob.Properties.LeaseState = BlobHttpResponseParsers.GetLeaseState(reader.ReadElementContentAsString()); break; case Constants.LeaseDurationElement: blob.Properties.LeaseDuration = BlobHttpResponseParsers.GetLeaseDuration(reader.ReadElementContentAsString()); break; case Constants.CopyIdElement: copyId = reader.ReadElementContentAsString(); break; case Constants.CopyCompletionTimeElement: copyCompletionTime = reader.ReadElementContentAsString(); break; case Constants.CopyStatusElement: copyStatus = reader.ReadElementContentAsString(); break; case Constants.CopyProgressElement: copyProgress = reader.ReadElementContentAsString(); break; case Constants.CopySourceElement: copySource = reader.ReadElementContentAsString(); break; case Constants.CopyStatusDescriptionElement: copyStatusDescription = reader.ReadElementContentAsString(); break; default: reader.Skip(); break; } } } this.reader.ReadEndElement(); break; case Constants.MetadataElement: blob.Metadata = Response.ParseMetadata(this.reader); break; default: this.reader.Skip(); break; } } } this.reader.ReadEndElement(); Uri uri = NavigationHelper.AppendPathToSingleUri(baseUri, name); if (blob.SnapshotTime.HasValue) { UriQueryBuilder builder = new UriQueryBuilder(); builder.Add("snapshot", BlobRequest.ConvertDateTimeToSnapshotString(blob.SnapshotTime.Value)); uri = builder.AddToUri(uri); } blob.StorageUri = new StorageUri(uri); if (!string.IsNullOrEmpty(copyStatus)) { blob.CopyState = BlobHttpResponseParsers.GetCopyAttributes( copyStatus, copyId, copySource, copyProgress, copyCompletionTime, copyStatusDescription); } return(new ListBlobEntry(name, blob)); }