I'm trying to simulate a resumable-upload to a GCS signed-url using Postman to do two PUT to see how it works.
After reference several posts:
Can I do a resumable upload with a Google Cloud Storage signed URL?
Uploading to Google Cloud using a signed URL
How to use gcs-resumable-upload with signed url
I finally made it and successfully get back the 200 OK, but the file is corrupted. Here are the steps:
0). POST to our server (running NodeJS 8.11) to get a bucket signed-url with action=="resumable". Server code is:
const file = bucket.file(fileName);
const config = {
action: 'resumable',
version: 'v4',
expires,
contentType
};
file.getSignedUrl( config, (error, url) => {
if (error) return reject(error);
resolve(url);
});
which will get back the signed-url as:
https://storage.googleapis.com/<bucket_name/<path_to_file>?GoogleAccessId=<service_account>&Expires=<expiry_time>&Signature=<signature>
1). POST to the signed url with header { 'x-goog-resumable': 'start' }
and an empty body. I got back HTTP 201 created, and the "Location" header with value same as the signed-url, plus the &upload_id=AEnB2UqIJL_jf.....
at the end, also the "X-GUploader-UploadID" header with the upload_id.
2). To simulate 2 uploads for a single file size of 730417, first PUT to the "Location" returned from (1), with Headers:
Content-Length: 262144
Content-Range: bytes 0-262143/730417
Content-Type: application/pdf
and in Postman select body as "binary" and choose the source file. I received the response of HTTP 308 (Resume Incomplete) and in the response header:
Content-Type: text/plain; charset=utf-8
Range: bytes=0-262143
X-Range-MD5: ccafa0beacd8c342bb460b95249114dc
X-GUploader-UploadID: AEnB2UqIJL_jf.....
3). To check the current upload status, following step (2) I do a PUT to same "Location" url, with empty body and header:
Content-Length: 0
Content-Range: bytes */730417
I got back same HTTP 308 (Resume Incomplete) as in (2), and response header:
Content-Type: text/plain; charset=utf-8
X-GUploader-UploadID: (same_upload_id)
Range: bytes=0-262143
X-Range-MD5: ccafa0beacd8c342bb460b95249114dc
and at this moment, I still don't see the uploaded-file in my bucket yet from GCS bucket console.
4). So far so good, so I finish it up with 2nd part of PUT to same "Location" url with following header and select the body as "binary" and choose the same source file:
Content-Length: 468273
Content-Range: bytes 262144-730416/730417
Content-Type: application/pdf
and I got back HTTP 200 OK with response header:
x-goog-generation: 1568787913806411
x-goog-stored-content-length: 730417
ETag: "018677cb75c5a307217eec21fa18ee91"
Content-Length: 0
Content-Type: text/html; charset=UTF-8
and I can see the uploaded-file appeared in the GCS console.
5). The problem now is that: the file downloaded from GCS has the same byte-count as the source file, but MD5 checksum mismatch with the source file. The source file is a 3 page PDF file, and the uploaded file, after downloaded it, has only the last page.
What could go wrong ? ... did I do anything wrong in Postman steps ? ... The steps seems to follow the steps here https://cloud.google.com/storage/docs/xml-api/resumable-upload properly, but the corrupted content is quite mystery to me, and I'm not sure where to troubleshoot this ... maybe using another client to try the resumable upload to signed-url ? ... any suggestion is very much appreciated, Thanks !