(Updated to show the latest request and results)
I'm trying to use HTTP requests to send a batch delete request to Google Cloud Storage. Per this document:
https://cloud.google.com/storage/docs/batch
and some experimentation and google-ing, it almost works - all but the last file is deleted.
curl --location --request POST 'https://www.googleapis.com/batch/storage/v1' \
--header "Content-Type: multipart/mixed; boundary='=========delete_AK-AKMLS_22-14540===='" \
--header "Authorization: Bearer MY_AUTH_TOKEN" \
--data-raw '--=========delete_AK-AKMLS_22-14540====
Content-Type: application/http
Content-ID: <1707427885-AK-AKMLS-22-14540-org/000.jpg>
DELETE /storage/v1/b/MY-BUCKET-NAME/o/AK-AKMLS%2F22-14540%2Forg%2F000.jpg
--=========delete_AK-AKMLS_22-14540====
Content-Type: application/http
Content-ID: <1707427885-AK-AKMLS-22-14540-org/001.jpg>
DELETE /storage/v1/b/MY-BUCKET-NAME/o/AK-AKMLS%2F22-14540%2Forg%2F001.jpg
--=========delete_AK-AKMLS_22-14540====
Content-Type: application/http
Content-ID: <1707427885-AK-AKMLS-22-14540-org/002.jpg>
DELETE /storage/v1/b/MY-BUCKET-NAME/o/AK-AKMLS%2F22-14540%2Forg%2F002.jpg
--=========delete_AK-AKMLS_22-14540====
Content-Type: application/http
Content-ID: <1707427885-AK-AKMLS-22-14540-org/003.jpg>
DELETE /storage/v1/b/MY-BUCKET-NAME/o/AK-AKMLS%2F22-14540%2Forg%2F003.jpg
--=========delete_AK-AKMLS_22-14540===='
In this case, the first 2 objects are deleted, but the 3rd one isn't. If I request 5 files to be deleted, 4 are deleted, but not the 5th. The response I got from Google for the request above:
--batch_V1mVEkG9XhCd0_MIf13rGYRrdVxZ0uO2
Content-Type: application/http
Content-ID: <response-1707427885-AK-AKMLS-22-14540-org/000.jpg>
HTTP/1.1 204 No Content
Content-Type: application/json
Date: Thu, 08 Feb 2024 21:33:13 GMT
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Content-Length: 0
--batch_V1mVEkG9XhCd0_MIf13rGYRrdVxZ0uO2
Content-Type: application/http
Content-ID: <response-1707427885-AK-AKMLS-22-14540-org/001.jpg>
HTTP/1.1 204 No Content
Content-Type: application/json
Date: Thu, 08 Feb 2024 21:33:13 GMT
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Content-Length: 0
--batch_V1mVEkG9XhCd0_MIf13rGYRrdVxZ0uO2
Content-Type: application/http
Content-ID: <response-1707427885-AK-AKMLS-22-14540-org/002.jpg>
HTTP/1.1 204 No Content
Content-Type: application/json
Date: Thu, 08 Feb 2024 21:33:13 GMT
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Content-Length: 0
--batch_V1mVEkG9XhCd0_MIf13rGYRrdVxZ0uO2--
Per the Google doc, I expected the responses to be "HTTP/1.1 200 OK", not "204 No Content". And the "Expires" being "01 Jan 1990" is also weird. But the weirdest is that, even though the response for each section is the same, the first two objects are deleted, but the third one isn't.
This is a working curl example
curl --location --request POST 'https://www.googleapis.com/batch/storage/v1' \
--header 'Content-Type: multipart/mixed; boundary=77777' \
--header 'Authorization: Bearer {token}' \
--data-raw '--77777
Content-Type: application/http
Content-ID: 1
DELETE /storage/v1/b/{bucket name}/o/TEMP%2F1572593856429.jpg
--77777
Content-Type: application/http
Content-ID: 2
DELETE /storage/v1/b/{bucket name}/o/TEMP%2F1572603280427.jpg
--77777
Content-Type: application/http
Content-ID: 3
DELETE /storage/v1/b/{bucket name}/o/TEMP%2F1573650760693.jpg
--77777--'