Where does m.lcToken come from?
On 13/05/2022 13:36, Frank Cazabon wrote:
Hi Ed,
unfortunately I'm not getting it to work (either from VFP or from Postman).
Here is what I have tried in VFP:
m.lcAccountNumber = "999999" && 6 digit customer number
m.lcSourceFile = "/PensionDocuments/0003598C-466F-9A42-1C5E-F38944279108.pdf" m.lcDestFile = "/FRANK-Test/pensions/0003598C-466F-9A42-1C5E-F38944279108.pdf"
m.lcBaseUrl = "https://ord.blockstorage.api.rackspacecloud.com/v1/" + m.lcAccountNumber
loXmlHttp.Open( "PUT" , m.lcBaseUrl + m.lcDestFile, .F. ) loXmlHttp.setRequestHeader("X-Auth-Token", m.lcToken) loXmlHttp.setRequestHeader("X-Copy-From", m.lcBaseUrl + m.lcSourceFile) loXmlHttp.setRequestHeader("Content-Length", 0) loXmlHttp.Send()
? "===================================" ? loXmlHttp.Status ? loXmlHttp.responsetext ? "==================================="
What I get back is: Status 404, the resource could not be found.
Can you see what I am doing wrong?
Frank.
Frank Cazabon
On 12/05/2022 3:06 pm, Ed Leafe wrote:
On May 12, 2022, at 13:10, Frank Cazabon frank.cazabon@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
[excessive quoting removed by server]