[GH-ISSUE #296] Issue with the filesystem backend #59

Open
opened 2026-03-03 12:07:54 +03:00 by kerem · 4 comments
Owner

Originally created by @bkhanale on GitHub (Jul 27, 2020).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/296

I'm trying to upload files to a local filesystem. As I upload they get saved to the root dir and once I'm done with the server, I close it and start again when needed. Unfortunately when I restart server all of the /download/... links don't return the data correctly. For example when I upload a .mp3 file with Content-Type: audio/mpeg and tried to download it through the endpoint I just get a plain text output without any Content-Type set (after server restart).

I tried to look over the code and I realise that it's not able to set any content type here. I tried to do it manually to test and even though I don't get plain text anymore the file content itself does not look correct (the browser doesn't get to play the file). I wasn't able to figure out the reason behind this issue.

Let me know if you need some more data to replicate or work with this issue.

Originally created by @bkhanale on GitHub (Jul 27, 2020). Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/296 I'm trying to upload files to a local filesystem. As I upload they get saved to the root dir and once I'm done with the server, I close it and start again when needed. Unfortunately when I restart server all of the `/download/...` links don't return the data correctly. For example when I upload a `.mp3` file with `Content-Type: audio/mpeg` and tried to download it through the endpoint I just get a plain text output without any `Content-Type` set (after server restart). I tried to look over the code and I realise that it's not able to set any content type [here](https://github.com/fsouza/fake-gcs-server/blob/main/internal/backend/fs.go#L166). I tried to do it manually to test and even though I don't get plain text anymore the file content itself does not look correct (the browser doesn't get to play the file). I wasn't able to figure out the reason behind this issue. Let me know if you need some more data to replicate or work with this issue.
Author
Owner

@fsouza commented on GitHub (Jul 27, 2020):

Hey, thanks for reporting this issue.

If you save the file locally is the content correct? Like can you play the mp3 file if you curl it?

Do you have a simple reproducer? I can check this out later today.

Does it work if you use the memory backend?

<!-- gh-comment-id:664635165 --> @fsouza commented on GitHub (Jul 27, 2020): Hey, thanks for reporting this issue. If you save the file locally is the content correct? Like can you play the mp3 file if you curl it? Do you have a simple reproducer? I can check this out later today. Does it work if you use the memory backend?
Author
Owner

@bkhanale commented on GitHub (Jul 28, 2020):

If you save the file locally is the content correct? Like can you play the mp3 file if you curl it?

I can't, it just saves the whole thing as a json. Like this here. I don't know if it is supposed to be saved that way. The filename is correct though.

Do you have a simple reproducer? I can check this out later today.

Yeah, so I'm uploading the file like this:

storage_client = storage.Client(
    credentials=AnonymousCredentials(),
    project="test",
    client_options=ClientOptions(api_endpoint=EXTERNAL_URL)
)
bucket = storage_client.lookup_bucket(bucket_name)
blob = bucket.blob(file_data.name)
content_type = mimetypes.guess_type(file_data.name, strict=False)[0]
blob.upload_from_file(file_data, content_type=content_type)

This uploads the file fine, I can see the file in my media dir. On requesting to download the file through /download/... endpoint I do get the file downloaded properly. But if I restart the server and access the same link again, I just get a plain text response instead of the file itself.

Does it work if you use the memory backend?

Yes, it does I guess hoping that it is used when the server is not restarted. Correct me if I'm wrong. @fsouza

<!-- gh-comment-id:664808057 --> @bkhanale commented on GitHub (Jul 28, 2020): >If you save the file locally is the content correct? Like can you play the mp3 file if you curl it? I can't, it just saves the whole thing as a json. Like this [here](https://paste.bhushan.codes/?56ca37895f305f3c#3CvZcsqX2ZFdsMn7HdXVLGDNtWRtisQRobBU9qmwC2VT). I don't know if it is supposed to be saved that way. The filename is correct though. >Do you have a simple reproducer? I can check this out later today. Yeah, so I'm uploading the file like this: ```py storage_client = storage.Client( credentials=AnonymousCredentials(), project="test", client_options=ClientOptions(api_endpoint=EXTERNAL_URL) ) bucket = storage_client.lookup_bucket(bucket_name) blob = bucket.blob(file_data.name) content_type = mimetypes.guess_type(file_data.name, strict=False)[0] blob.upload_from_file(file_data, content_type=content_type) ``` This uploads the file fine, I can see the file in my media dir. On requesting to download the file through `/download/...` endpoint I do get the file downloaded properly. But if I restart the server and access the same link again, I just get a plain text response instead of the file itself. >Does it work if you use the memory backend? Yes, it does I guess hoping that it is used when the server is not restarted. Correct me if I'm wrong. @fsouza
Author
Owner

@fsouza commented on GitHub (Jul 28, 2020):

@bkhanale gotcha, I think the filesystem backend doesn't persist metadata currently, we need to implement that :(

<!-- gh-comment-id:665066123 --> @fsouza commented on GitHub (Jul 28, 2020): @bkhanale gotcha, I think the filesystem backend doesn't persist metadata currently, we need to implement that :(
Author
Owner

@fsouza commented on GitHub (Feb 15, 2021):

(I think this maybe due to how we store the actual file content. Need to revisit, maybe use base64 for bytes, idk)

<!-- gh-comment-id:779484432 --> @fsouza commented on GitHub (Feb 15, 2021): (I think this maybe due to how we store the actual file content. Need to revisit, maybe use base64 for bytes, idk)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#59
No description provided.