ReURL形式下如何进行PUT操作
一个签名URL的python 实现例子。
'''
Test put object with Signed URL
'''
host = get_host()
method = "PUT"
bucket = "test" time.strftime("%Y-%b-%d%H-%M-%S").lower()
object = "test_object"
url = "/" bucket "/" object
resource = "/" bucket "/" object
content_type = "text/plain"
#1. create a bucket
res = self.oss.put_bucket(bucket)
self.assertEqual(res.status, 200)
#2.sign a URL with put method
headers = {}
headers["Content-Type"] = content_type
headers["x-oss-meta-test"] = content_type
timeout = 60
url_with_auth = self.oss.sign_url_auth_with_expire_time(method, url, headers, resource, timeout)
#3.get a normal HTTP connect and send content to object
conn = get_conn_by_host(host)
conn.putrequest(method, url_with_auth)
filesize = os.path.getsize(self.put_file)
conn.putheader("Content-Length", str(filesize))
conn.putheader("Content-Type", content_type)
conn.putheader("Content-Language", content_type)
conn.putheader("x-oss-meta-test", content_type)
conn.endheaders()
original_content = ""
fp = open(self.put_file, "rb")
l = fp.read(self.oss.SendBufferSize)
while len(l) > 0:
conn.send(l)
l = fp.read(self.oss.SendBufferSize)
original_content = l
res = conn.getresponse()