尝试从存储分区

时间:2017-05-07 13:16:26

标签: python-2.7 google-app-engine google-cloud-storage

我正在尝试通过cloudstorage api从Google云端存储中删除文件(视频),但是虽然该文件存在,但我收到以下错误:

cloudstorage.delete('/catchamove-video/products/6411421952770048.mp4')

*** NotFoundError: Expect status [204] from Google Storage. But got status 404.
Path: '/catchamove-video/products/6411421952770048.mp4'.
Request headers: None.
Response headers: {'transfer-encoding': 'chunked', 'date': 'Sun, 07 May 2017 12:31:47 GMT', 'server': 'Development/2.0'}.
Body: ''.
Extra info: None.

存储桶和文件都出现在控制台上。

1 个答案:

答案 0 :(得分:0)

我正面临着同样的问题:通过REST API删除文件夹时得到404。

经过一些测试,我弄清楚了如何删除GCP存储的文件夹-

必须删除文件夹中的所有文件(对象),子文件夹和子文件夹以及文件夹中的文件。请注意,删除空文件夹时,您仍然可能会看到“ 404 Not Found”(通常为204),只要忽略它,空文件夹就会被实际删除。

示例:

curl -I -X DELETE -H "Authorization: Bearer <author_code>" https://www.googleapis.com/storage/v1/b/<bucket_name>/o/folder%2Fsub-folder%2Ffile1

curl -I -X DELETE -H "Authorization: Bearer <author_code>" https://www.googleapis.com/storage/v1/b/<bucket_name>/o/folder%2Fsub-folder%2Ffile2

curl -I -X DELETE -H "Authorization: Bearer <author_code>" https://www.googleapis.com/storage/v1/b/<bucket_name>/o/folder%2Fsub-folder%2F  #May get 204 or 404 response code

curl -I -X DELETE -H "Authorization: Bearer <author_code>" https://www.googleapis.com/storage/v1/b/<bucket_name>/o/folder%2F #May get 204 or 404 response code

注意:URL中的“%2F”实际上是“ /”字符