2015-11-26 28 views
0

我試圖找到一種方法來更改上傳到s3存儲桶時使用的http方法(POST/PUT)與boto3 python的庫,我一直無法找到如何做到這一點,任何幫助將不勝感激。如何更改boto3中的http方法

謝謝。

+1

什麼讓你覺得POST是支持S3桶?我的理解是HTTP動詞被boto3封裝爲's3.Object().get()','s3.Object.put()'等,並根據文檔(http://boto3.readthedocs .org/en/latest/reference/services/s3.html#object)post()未實現。 –

+0

POST是[supported](http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPOST.html),但我沒有任何理由在瀏覽器之外使用它。 –

回答

0

爲此,您需要註冊event。您可以在botocore中看到一個示例。我很好奇你爲什麼想要這樣做,因爲它只會讓你的表單變得更加困難,因爲它強制你編碼請求,就好像它是從HTML表單提交的一樣。

複製爲後人:

def change_get_to_post(request, **kwargs): 
# This is useful when we need to change a potentially large GET request 
# into a POST with x-www-form-urlencoded encoding. 
if request.method == 'GET' and '?' in request.url: 
    request.headers['Content-Type'] = 'application/x-www-form-urlencoded' 
    request.method = 'POST' 
    request.url, request.data = request.url.split('?', 1) 
+0

事實證明,帖子沒有在boto3中實現,所以這是一種方法,或者只是使用請求來實現整個事情。謝謝。 – Miguel