Thank you for visiting the Rackspace Community
The Community is live! Post new content or topics so our teams can assist.

Please contact your support team if you have a question or need assistance for any Rackspace products, services, or articles.

.NET SDK Cloud Files .. Upload Objects with Custom Headers

This question is answered.

I have a .NET application to store files in Cloud Files via .NET SDK. Below is the code I am using

Dim identity = New CloudIdentity With {.Username = username, .APIKey = api_key}
Dim createContainerResponse = cloudFilesProvider.CreateContainer("XPERT" & Session("CustCode"))
Dim metadata = New Dictionary(Of String, String)
metadata.Add("X-Object-Meta-Projectcode", txtProject.Text)
metadata.Add("X-Object-Meta-Filedesc", txtDesc.Text)
metadata.Add("X-Object-Meta-Usercode", Session("UserCode"))
metadata.Add("X-Detect-Content-Type", "true")
cloudFilesProvider.CreateObject("XPERT" & Session("CustCode"), stream, filename, , , metadata)

The files are uploading correctly, but the Meta data (Custom Headers) are not reflected. Is there anything I am missing in my code. Any assistance will be highly appreciated.

Verified Answer
  • I have managed to filter the files based on the Metadata of the files, below is a code snippet in VB.NET with OpenStack SDK. Hope it could be useful for someone.

    Dim identity = New CloudIdentity With {.Username = username, .APIKey = api_key}

    Dim cloudFilesProvider = New CloudFilesProvider(identity)

     

    Dim DS As New DataSet

    DS.Tables.Add("MySet")

    DS.Tables(0).Columns.Add("FileName")

    DS.Tables(0).Columns.Add("FileDesc")

    DS.Tables(0).Columns.Add("UploadedBy")

     

    Dim containerObject As ContainerObject

    Dim DR As DataRow

     

    For Each containerObject In containerObjectList

    Dim metadata As Dictionary(Of String, String) = cloudFilesProvider.GetObjectMetaData("XPERT" & Session("CustCode"), containerObject .Name)

    If metadata("Projectcode") = txtPjtCode.Text Then

    DR = DS.Tables(0).Rows.Add

    DR("FileName") = cO.Name

    DR("FileDesc") = metadata("Filedesc")

    DR("UploadedBy") = metadata("Usercode")

    End If

    Next

    ‘Now You can use the DS (Dataset) to bind it to any control

All Replies
  • Hi mhvraju,

    I've reached out to some of our .NET developers to provide an answer for you and will update this accordingly.

    Regards,

    ReisH

  • Hi mhvraju,

    Where are you looking for the metadata to be reflected? Are you trying to retrieve it through the API or through the control panel?

    The developer I was liaising with also provided this test you can view.

    Regards,

    ReisH

  • Hello ReisH,
     
    Thank you for the information., I am checking through Control Panel for the Headers.
    I will check now the link you have sent and give feedback.
     
    Regards,
    Harsha.
     
    From: ReisH [mailto:bounce-BigR@community.rackspace.com]
    Sent: 10 February 2014 17:26
    To: developerforum@community.rackspace.com
    Subject: RE: [Developer Forum] .NET SDK Cloud Files .. Upload Objects with Custom Headers
     

    Hi mhvraju,

    Where are you looking for the metadata to be reflected? Are you trying to retrieve it through the API or through the control panel?

    The developer I was liaising with also provided this test you can view.

    Regards,

    ReisH

  • Hi,
     
    I have tested for the meta data through the API and indeed the values are there. They are not displaying in the control panel. One of the question is solved thank you.
     
    Now can I extract list of objects in a container with a specific metadata condition. For example ProjectCode like ‘XPERT’ should retrieve all the objects which have that header information.
     
    Once again, thank you very much for your effort on this.
     
    Regards,
    Harsha.
     
    From: Harsha - IMS Guru [mailto:harsha@imsguru.com]
    Sent: 10 February 2014 17:49
    To: 'developerforum@community.rackspace.com'
    Subject: RE: [Developer Forum] .NET SDK Cloud Files .. Upload Objects with Custom Headers
     
    Hello ReisH,
     
    Thank you for the information., I am checking through Control Panel for the Headers.
    I will check now the link you have sent and give feedback.
     
    Regards,
    Harsha.
     
    From: ReisH [mailto:bounce-BigR@community.rackspace.com]
    Sent: 10 February 2014 17:26
    To: developerforum@community.rackspace.com
    Subject: RE: [Developer Forum] .NET SDK Cloud Files .. Upload Objects with Custom Headers
     

    Hi mhvraju,

    Where are you looking for the metadata to be reflected? Are you trying to retrieve it through the API or through the control panel?

    The developer I was liaising with also provided this test you can view.

    Regards,

    ReisH

  • Hi Harsha,

    That's correct, the headers you're attempting to see through the control panel will not be displayed as at present we only show a specific subset of additional headers on files in the control panel:

    Access-Control-Allow-Credentials
    Access-Control-Allow-Methods
    Access-Control-Allow-Origin
    Access-Control-Expose-Headers
    Access-Control-Max-Age
    Access-Control-Request-Headers
    Access-Control-Request-Method
    Origin
    Content-Encoding
    Content-Disposition
    X-Delete-After
    X-Delete-At
    X-Object-Manifest

    To achieve the list of objects which match your criteria; you can use this call to iterate over the metadata of all the objects in the container and then get the objects where these match but  I don't have a code example for this.

    Regards,

    ReisH

  • I have managed to filter the files based on the Metadata of the files, below is a code snippet in VB.NET with OpenStack SDK. Hope it could be useful for someone.

    Dim identity = New CloudIdentity With {.Username = username, .APIKey = api_key}

    Dim cloudFilesProvider = New CloudFilesProvider(identity)

     

    Dim DS As New DataSet

    DS.Tables.Add("MySet")

    DS.Tables(0).Columns.Add("FileName")

    DS.Tables(0).Columns.Add("FileDesc")

    DS.Tables(0).Columns.Add("UploadedBy")

     

    Dim containerObject As ContainerObject

    Dim DR As DataRow

     

    For Each containerObject In containerObjectList

    Dim metadata As Dictionary(Of String, String) = cloudFilesProvider.GetObjectMetaData("XPERT" & Session("CustCode"), containerObject .Name)

    If metadata("Projectcode") = txtPjtCode.Text Then

    DR = DS.Tables(0).Rows.Add

    DR("FileName") = cO.Name

    DR("FileDesc") = metadata("Filedesc")

    DR("UploadedBy") = metadata("Usercode")

    End If

    Next

    ‘Now You can use the DS (Dataset) to bind it to any control

  • Fantastic!  I'm glad you've got it working as expected and thank you for contributing the code you used, I'm sure it will be helpful for other members Yes

    Regards,

    ReisH

  • Though the code above is giving the solution for what is required, when you have thousands of files in the container, checking metadata of each file would require lot of processing. This code, I think is very primitive, this question is still open for improvements.

  • Hi mhvraju,

    Cloud Files does not support bulk queries to metadata for objects stored in a container, and is not designed for this type of use (especially at a large scale). If you need to perform this type of operation efficiently, you'll need to store your metadata independently of Cloud Files itself.

    The feature you would need before this is a realistic solution is currently referred to as Searchable Metadata by the following blueprint:
    https://blueprints.launchpad.net/swift/+spec/searchable-metadata

    Thanks,
    Sam

  • Small update on this issue is, I have appended a prefix for all the uploaded to cloud files. This has helped me to avoid going through all the files in the container to extract the related files. This has reduced a lot of delay in extracting the objects list related to a specific file. I have used the below code:

    containerObjectList = cloudFilesProvider.ListObjects("XPERT", prefix:=MyRequiredPrefix)

    This was particularly useful, as I upload documents related to each transaction, I have just appended the transaction number at the beginning of the file name. If this "prefix" parameter can accept regular expressions, we can do wonders with Cloud Files with very basic programming not going into complex technologies.