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?
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:
UpdateObjectMetadata
call after you create the object.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. :)