Skip to content

Commit 7cc53f2

Browse files
committed
Preserve content type of objects during metadata update operations (fixes #192)
1 parent 1d71532 commit 7cc53f2

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/corelib/Providers/Rackspace/CloudFilesProvider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,11 @@ public void UpdateObjectMetadata(string container, string objectName, Dictionary
808808

809809
var urlPath = new Uri(string.Format("{0}/{1}/{2}", GetServiceEndpointCloudFiles(identity, region, useInternalUrl), _encodeDecodeProvider.UrlEncode(container), _encodeDecodeProvider.UrlEncode(objectName)));
810810

811-
ExecuteRESTRequest(identity, urlPath, HttpMethod.POST, headers: headers);
811+
RequestSettings settings = BuildDefaultRequestSettings();
812+
// make sure the content type is not changed by the metadata operation
813+
settings.ContentType = null;
814+
815+
ExecuteRESTRequest(identity, urlPath, HttpMethod.POST, headers: headers, settings: settings);
812816
}
813817

814818
/// <inheritdoc />

src/testing/integration/Providers/Rackspace/UserObjectStorageTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,19 +864,23 @@ public void TestUpdateObjectMetaData()
864864
string containerName = TestContainerPrefix + Path.GetRandomFileName();
865865
string objectName = Path.GetRandomFileName();
866866
string objectData = "";
867+
string contentType = "text/plain-jane";
867868

868869
ObjectStore result = provider.CreateContainer(containerName);
869870
Assert.AreEqual(ObjectStore.ContainerCreated, result);
870871

871872
Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(objectData));
872-
provider.CreateObject(containerName, stream, objectName);
873+
provider.CreateObject(containerName, stream, objectName, contentType);
874+
Assert.AreEqual(contentType, GetObjectContentType(provider, containerName, objectName));
875+
873876
Dictionary<string, string> metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
874877
{
875878
{ "Key1", "Value 1" },
876879
{ "Key2", "Value ²" },
877880
};
878881

879882
provider.UpdateObjectMetadata(containerName, objectName, new Dictionary<string, string>(metadata, StringComparer.OrdinalIgnoreCase));
883+
Assert.AreEqual(contentType, GetObjectContentType(provider, containerName, objectName));
880884

881885
Dictionary<string, string> actualMetadata = provider.GetObjectMetaData(containerName, objectName);
882886
Console.WriteLine("Object Metadata");
@@ -891,6 +895,7 @@ public void TestUpdateObjectMetaData()
891895
{ "Key2", "Value 2" }
892896
};
893897
provider.UpdateObjectMetadata(containerName, objectName, new Dictionary<string, string>(updatedMetadata, StringComparer.OrdinalIgnoreCase));
898+
Assert.AreEqual(contentType, GetObjectContentType(provider, containerName, objectName));
894899

895900
actualMetadata = provider.GetObjectMetaData(containerName, objectName);
896901
Console.WriteLine("Object Metadata");

0 commit comments

Comments
 (0)