Back

Uploading file with multipart

  • 0
  • Self Hosted
Nevus
17 Apr, 2023, 13:34

I am trying to upload file using storage api and go. When file size is a multiple of chunk size, it completes successfully. But if there is a small remaining part, then the request fails with status code 500 Server Error. The docker logs show:

TypeScript
Warning: file_get_contents(/storage/uploads/app-testsdk/testBucket/tmp_testFile.txt/testFile.part.8): Failed to open stream: No such file or directory in /usr/src/code/vendor/utopia-php/storage/src/Storage/Device/Local.php on line 124
[Error] Timestamp: 2023-04-17T13:30:18+00:00
[Error] Method: POST
[Error] URL: /v1/storage/buckets/:bucketId/files
[Error] Type: Exception
[Error] Message: Failed to read chunk /storage/uploads/app-testsdk/testBucket/tmp_testFile.txt/testFile.part.8
[Error] File: /usr/src/code/vendor/utopia-php/storage/src/Storage/Device/Local.php
[Error] Line: 126

What might be the issue?

TL;DR
Title: Issue uploading file with multipart in Go SDK Messages: There is an issue with uploading files using the storage API and the Go SDK. When the file size is not a multiple of the chunk size, the request fails with a 500 Server Error. The error message indicates that the last chunk cannot be read. This problem does not occur with the Appwrite cloud. Solution: There is currently no solution provided in the support thread.
Nevus
17 Apr, 2023, 13:35

I am using chunk size of 1024 and size of 7168(7 chunks) completes successfully but file of size 7173 fails.

Nevus
17 Apr, 2023, 13:35

The last content range header is bytes 7168-7172/7173

joeyouss
17 Apr, 2023, 14:55

Hi - let me look into this

Nevus
17 Apr, 2023, 16:08

Not sure how relevant this is but I tried tracking the directory where appwrite stores the files:

TypeScript
/storage/uploads/app-testsdk/testBucket/tmp_test12MB.txt # cat test12MB.txt_chunks.log 
1
2
6

The last line shouldn't be 6? I am using appwrite 1.3.1 and the same code works with appwrite cloud.

joeyouss
17 Apr, 2023, 16:24

Have you used our official SDKs for file upload, or are you doing chunking yourself.

Nevus
17 Apr, 2023, 16:27

I am writing an SDK for go. The current one doesn't support chunking 😅

Nevus
17 Apr, 2023, 16:29

I dont think its a problem with chunking since it works with appwrite cloud.

Nevus
17 Apr, 2023, 18:11

I finally figured it out: For the last block, the end byte must be equal to total size. For a file size of 7173, the final header should be bytes 7168-7173/7173. However, this seems to be wrong because:

  1. According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range

    Content-Range: <unit> <range-start>-<range-end>/<size> <range-end> An integer in the given unit indicating the end position (zero-indexed & inclusive) of the requested range. Range end should be inclusive.

  2. According to https://httpwg.org/specs/rfc9110.html#field.content-range

    A Content-Range field value is invalid if it contains a range-resp that has a last-pos value less than its first-pos value, or a complete-length value less than or equal to its last-pos value. The recipient of an invalid Content-Range MUST NOT attempt to recombine the received content with a stored representation. range-end must be less than complete-length

Nevus
17 Apr, 2023, 19:02

Opened a github issue cause this probably belong there

joeyouss
18 Apr, 2023, 14:57

please paste the link here as well ❤️

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more