如何使用 python 在 Swift Storage 系统中上传文件?

Ame*_*lie 5 python openstack-swift python-2.7

我想用 Swift 上传文件。我在 python 中执行了这段代码:

 import swiftclient
swift = swiftclient.client.Connection(auth_version='1',user='test:tester',key='testing',authurl='http://localhost:8080/auth/v1.0')
# Create the swift container
swift.put_container('cute-cats')
# Upload the object
with open('cat.jpg', 'rb') as f:
    file_data = f.read()
swift.put_object('cute-cats', 'cat.jpg', file_data)

# List the containers
print swift.head_account()

# List the objects in the cute cats containers
print swift.head_container('cute-cats')
Run Code Online (Sandbox Code Playgroud)

代码正在运行,但是,如何检查文件是否存储在 swift 中?Swift 文件夹中不存在该文件。

谢谢。

Nel*_*cos 1

从终端你可以运行一个简单的curl:

$curl http://localhost:8080/v1/AUTH_test/cute-cats/cat.jpg

如果您想使用 python 代码进行测试,可以使用 lib requests 1

Swift 文件夹中不存在该文件。

你指的是哪个文件夹?Swift 通常使用哈希来存储其对象(文件),因此要查找对象,您需要像 swift-get-nodes 这样的命令。