OpenStack .NET API , meta data not getting added when passed in with cloudFilesProvider.CreateObjectFromFile

StackOverflow https://stackoverflow.com/questions/18085996

Question

Unable to add metadata while creating object with cloudFilesProvider.CreateObjectFromFile. Is that supported by cloudFilesProvider.CreateObjectFromFile? Currently i'm doing:

DicMetaData.Add("StoreID", inStrContainerID);
DicMetaData.Add("FileType", instrFileType);
DicMetaData.Add("DateCreated", dTDateCreated.ToString("MM/dd/yyyy hh:mm:ss.FFF"));
DicMetaData.Add("isProcessed", "0");
DicMetaData.Add("DateProcessed", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.FFF"));

cloudFilesProvider.CreateObjectFromFile(inStrContainerID, inStrSrcFilePath, strDesFileName, 4096, DicMetaData);

So while calling cloudFilesProvider.CreateObjectFromFile i stepped in all they way to

RestService.Stream(absoluteUri, method, stream, chunkSize, maxReadLength, headers, queryStringParameter, requestSettings, progressUpdated);

in StreamRESTRequest method of ProviderBase.cs and here the headers count was 6 [5 items i added + X-Auth-Token that gets added before RestService.Stream]

so i know all the items are getting passed to the resquest, but after the object is created, if i do a get cloudFilesProvider.GetObjectMetaData then i get a Dictionary back with count 0.

Then i did

cloudFilesProvider.CreateObjectFromFile(inStrContainerID, inStrSrcFilePath, strDesFileName);
cloudFilesProvider.UpdateObjectMetadata(inStrContainerID, strDesFileName, DicMetaData);

here if i do a get cloudFilesProvider.GetObjectMetaData i get the added metadata back in the Dictionary.

So how can this be done better?

Was it helpful?

Solution

It looks like you're calling the method with an unexpected argument. The CreateObjectFromFile method takes a headers dictionary, which is actually the raw HTTP headers to add to the request. Since the Metadata class is derived from Dictionary<string, string>, your code still compiles when you pass a Metadata for this argument, yet the result is not as you'd expect.

There is no direct support in the SDK for including a Metadata object in the call to CreateObjectFromFile. In addition, the OpenStack Object Storage API Reference does not include any information about including headers in the underlying Create Object API method.

You have two ways you can approach this problem:

  1. Use the documented UpdateObjectMetadata call after you create the object.
  2. Attempt to use an undocumented feature of adding X-Object-Meta-xxx metadata in the headers passed to the CreateObjectFromFile method (this may or may not work, may vary between OpenStack implementations, and may change behavior at any time).

Obviously I recommend you stick with the documented method. :)

OTHER TIPS

So for those curious, i did experiment with option 2 from this anwser :

DicMetaData.Add("X-Object-Meta-StoreID", inStrContainerID);
DicMetaData.Add("X-Object-Meta-FileType", instrFileType);
DicMetaData.Add("X-Object-Meta-DateFileCreated", dTDateCreated.ToString("MM/dd/yyyy hh:mm:ss.FFF"));
DicMetaData.Add("X-Object-Meta-isProcessed", "0");
DicMetaData.Add("X-Object-Meta-DateProcessed", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.FFF"));

cloudFilesProvider.CreateObjectFromFile(inStrContainerID, inStrSrcFilePath, strDesFileName, 4096, DicMetaData);

Metadata = cloudFilesProvider.GetObjectMetaData(inStrContainerID, inStrFileName);

and ended up raising more issues.

The meta tags did get added to the files but the tag names got changes a little bit. for entry X-Object-Meta-isProcessed i expected a tag called isProcessed and when i did a cloudFilesProvider.GetObjectMetaData the tag name was Isprocessed

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top