Skip to content
kukhariev edited this page Nov 11, 2022 · 1 revision

Upload files to S3 using presigned URLs

create multipart upload:

POST /files HTTP/1.1

Authorization: Bearer dXNlcjpwYXNz
Content-Type: application/json; charset=UTF-8
Host: example.com
Origin: http://example.com
X-Upload-Content-Length: 21804129
X-Upload-Content-Type: video/mp4

{
  "name": "videofile.mp4",
  "mimeType": "video/mp4",
  "size": 21804129,
  "lastModified": 1638347731000
}
HTTP/1.1 201 Created
Access-Control-Allow-Origin: http://example.com
Access-Control-Expose-Headers: Location
Location: //example.com/files?upload_id=f8048cee0976d141-60a53b68e983de7e-9aa649a809275708
Content-Type: application/json

{
  "bytesWritten": 0,
  "name": "f8048cee0976d141-60a53b68e983de7e-9aa649a809275708",
  "metadata": {
    "name": "videofile.mp4",
    "mimeType": "video/mp4",
    "size": 21804129,
    "lastModified": 1638347731000
  },
  "originalName": "videofile.mp4",
  "contentType": "video/mp4",
  "size": 21804129,
  "id": "f8048cee0976d141-60a53b68e983de7e-9aa649a809275708",
  "UploadId": "ceadb011-c451-4d96-b4ce-696945badeb8",
  "partSize": 16777216,
  "status": "part",
  "Parts": [],
  "partsUrls": [
    "http://s3storage.com/node-uploadx/f8048cee0976d141-60a53b68e983de7e-9aa649a809275708?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=tomtiIQDZuKA3XKi%2F20220202%2Feu-west-3%2Fs3%2Faws4_request&X-Amz-Date=20220202T002222Z&X-Amz-Expires=3600&X-Amz-Signature=5a541b885b961320cae1142b9c6c6465d3331ed94d22247dbc47e968cf098412&X-Amz-SignedHeaders=host&partNumber=1&uploadId=ceadb011-c451-4d96-b4ce-696945badeb8&x-id=UploadPart",
    "http://s3storage.com/node-uploadx/f8048cee0976d141-60a53b68e983de7e-9aa649a809275708?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=tomtiIQDZuKA3XKi%2F20220202%2Feu-west-3%2Fs3%2Faws4_request&X-Amz-Date=20220202T002222Z&X-Amz-Expires=3600&X-Amz-Signature=e88680f51de4553388540893bd4281726b421db2ea7bc80796ded2885197f493&X-Amz-SignedHeaders=host&partNumber=2&uploadId=ceadb011-c451-4d96-b4ce-696945badeb8&x-id=UploadPart"
  ]
}

send part:

PUT http://s3storage.com/node-uploadx/f8048cee0976d141-60a53b68e983de7e-9aa649a809275708?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=tomtiIQDZuKA3XKi%2F20220202%2Feu-west-3%2Fs3%2Faws4_request&X-Amz-Date=20220202T002222Z&X-Amz-Expires=3600&X-Amz-Signature=5a541b885b961320cae1142b9c6c6465d3331ed94d22247dbc47e968cf098412&X-Amz-SignedHeaders=host&partNumber=1&uploadId=ceadb011-c451-4d96-b4ce-696945badeb8&x-id=UploadPart HTTP/1.1

Content-Length: 16777216
Host: s3storage.com
Origin: http://example.com

[0-16777216]
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://example.com
Access-Control-Expose-Headers: Etag
Content-Length: 0
ETag: "7d6ceca7eb2470a6c110000a7e17f635"

get info:

PATCH /files?upload_id=f8048cee0976d141-60a53b68e983de7e-9aa649a809275708 HTTP/1.1

Authorization: Bearer dXNlcjpwYXNz
Content-Type: application/json; charset=UTF-8
Host: example.com
Origin: http://example.com

{
  "partSize": 16777216,
  "partsUrls": [
    "http://s3storage.com/node-uploadx/f8048cee0976d141-60a53b68e983de7e-9aa649a809275708?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=tomtiIQDZuKA3XKi%2F20220202%2Feu-west-3%2Fs3%2Faws4_request&X-Amz-Date=20220202T002222Z&X-Amz-Expires=3600&X-Amz-Signature=5a541b885b961320cae1142b9c6c6465d3331ed94d22247dbc47e968cf098412&X-Amz-SignedHeaders=host&partNumber=1&uploadId=ceadb011-c451-4d96-b4ce-696945badeb8&x-id=UploadPart",
    "http://s3storage.com/node-uploadx/f8048cee0976d141-60a53b68e983de7e-9aa649a809275708?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=tomtiIQDZuKA3XKi%2F20220202%2Feu-west-3%2Fs3%2Faws4_request&X-Amz-Date=20220202T002222Z&X-Amz-Expires=3600&X-Amz-Signature=e88680f51de4553388540893bd4281726b421db2ea7bc80796ded2885197f493&X-Amz-SignedHeaders=host&partNumber=2&uploadId=ceadb011-c451-4d96-b4ce-696945badeb8&x-id=UploadPart"
  ]
}
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://example.com
Access-Control-Expose-Headers: Location
Location: //example.com/files?upload_id=f8048cee0976d141-60a53b68e983de7e-9aa649a809275708
Content-Type: application/json

{
  "bytesWritten": 16777216,
  "name": "f8048cee0976d141-60a53b68e983de7e-9aa649a809275708",
  "metadata": {
    "name": "videofile.mp4",
    "mimeType": "video/mp4",
    "size": 21804129,
    "lastModified": 1638347731000
  },
  "originalName": "videofile.mp4",
  "contentType": "video/mp4",
  "size": 21804129,
  "id": "f8048cee0976d141-60a53b68e983de7e-9aa649a809275708",
  "UploadId": "ceadb011-c451-4d96-b4ce-696945badeb8",
  "partSize": 16777216,
  "status": "part",
  "Parts": [
        {
      "ETag": "\"7d6ceca7eb2470a6c110000a7e17f635\"",
      "PartNumber": 1
    }
  ],
  "partsUrls": [
    "http://s3storage.com/node-uploadx/f8048cee0976d141-60a53b68e983de7e-9aa649a809275708?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=tomtiIQDZuKA3XKi%2F20220202%2Feu-west-3%2Fs3%2Faws4_request&X-Amz-Date=20220202T002222Z&X-Amz-Expires=3600&X-Amz-Signature=5a541b885b961320cae1142b9c6c6465d3331ed94d22247dbc47e968cf098412&X-Amz-SignedHeaders=host&partNumber=1&uploadId=ceadb011-c451-4d96-b4ce-696945badeb8&x-id=UploadPart",
    "http://s3storage.com/node-uploadx/f8048cee0976d141-60a53b68e983de7e-9aa649a809275708?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=tomtiIQDZuKA3XKi%2F20220202%2Feu-west-3%2Fs3%2Faws4_request&X-Amz-Date=20220202T002222Z&X-Amz-Expires=3600&X-Amz-Signature=e88680f51de4553388540893bd4281726b421db2ea7bc80796ded2885197f493&X-Amz-SignedHeaders=host&partNumber=2&uploadId=ceadb011-c451-4d96-b4ce-696945badeb8&x-id=UploadPart"
  ]
}

send part:

PUT http://s3storage.com/node-uploadx/f8048cee0976d141-60a53b68e983de7e-9aa649a809275708?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=tomtiIQDZuKA3XKi%2F20220202%2Feu-west-3%2Fs3%2Faws4_request&X-Amz-Date=20220202T002222Z&X-Amz-Expires=3600&X-Amz-Signature=e88680f51de4553388540893bd4281726b421db2ea7bc80796ded2885197f493&X-Amz-SignedHeaders=host&partNumber=2&uploadId=ceadb011-c451-4d96-b4ce-696945badeb8&x-id=UploadPart HTTP/1.1

Content-Length: 5026913
Host: s3storage.com
Origin: http://example.com


[16777216-21804129]
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://example.com
Access-Control-Expose-Headers: Etag
Content-Length: 0
ETag: "14cede919412dcf3d648aaf20a58c828"

complete multipart upload:

PATCH /files?upload_id=f8048cee0976d141-60a53b68e983de7e-9aa649a809275708 HTTP/1.1

Authorization: Bearer dXNlcjpwYXNz
Content-Type: application/json; charset=UTF-8
Host: example.com
Origin: http://example.com

{
  "partSize": 16777216,
  "Parts": [
    {
      "ETag": "\"7d6ceca7eb2470a6c110000a7e17f635\"",
      "PartNumber": 1
    },
    {
      "ETag": "\"14cede919412dcf3d648aaf20a58c828\"",
      "PartNumber": 2
    }
  ]
}
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://example.com
Access-Control-Expose-Headers: Location
Location: //example.com/files?upload_id=f8048cee0976d141-60a53b68e983de7e-9aa649a809275708
Content-Type: application/json

{
  "bytesWritten": 21804129,
  "name": "f8048cee0976d141-60a53b68e983de7e-9aa649a809275708",
  "metadata": {
    "name": "videofile.mp4",
    "mimeType": "video/mp4",
    "size": 21804129,
    "lastModified": 1638347731000
  },
  "originalName": "videofile.mp4",
  "contentType": "video/mp4",
  "size": 21804129,
  "id": "f8048cee0976d141-60a53b68e983de7e-9aa649a809275708",
  "UploadId": "ceadb011-c451-4d96-b4ce-696945badeb8",
  "partSize": 16777216,
  "status": "completed",
  "uri": "http://s3storage.com/node-uploadx/f8048cee0976d141-60a53b68e983de7e-9aa649a809275708"
}