On May 12, 2022, at 13:10, Frank Cazabon <frank.caza...@gmail.com> wrote:
> 
> anybody here ever had to do anything with Rackspace's  Storage API to move 
> objects around?
> 
> I think I've seen Rackspace mentioned here before so I'm hoping.
> 
> I've got to copy a file from one container to another (actually it's a lot of 
> files but I'm just trying to prove the concept).

I wrote the Python SDK for Rackspace (actually, all of OpenStack), and here's 
the code for copying one object to another container:

    @_handle_container_not_found
    def copy_object(self, container, obj, new_container, new_obj_name=None, 
content_type=None):
        """
        Copies the object to the new container, optionally giving it a new name.
        If you copy to the same container, you must supply a different name.

        Returns the etag of the newly-copied object.

        You can optionally change the content_type of the object by supplying
        that in the 'content_type' parameter.
        """
        nm = new_obj_name or utils.get_name(obj)
        uri = "/%s/%s" % (utils.get_name(new_container), nm)
        copy_from = "/%s/%s" % (utils.get_name(container), utils.get_name(obj))
        headers = {"X-Copy-From": copy_from,
                "Content-Length": "0"}
        if content_type:
            headers["Content-Type"] = content_type
        resp, resp_body = self.api.method_put(uri, headers=headers)
        return resp.headers.get("etag")


To translate to English, the URI is the base URI for the service, with 
"/new_container/new_name" appended to it. "new_name" defaults to the original 
object's name, but if you supply a different name for the copied object, that 
one is used instead.

The headers contain an item "X-Copy-From", whose value is 
"/original_container/original_name", which tells the API where to copy from. 
The operation is a PUT. "COPY" is a non-standard method; I don't know what 
idiot wrote the documentation you cited. These are the HTTP methods: 
https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods

Hope that makes some sense. If not, please let me know what needs clarifying.


-- Ed Leafe







_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: 
https://leafe.com/archives/byMID/8479d6f8-8e81-4604-90ad-bb6ab1aad...@leafe.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to