Upload zip file as bytes


I’m trying to upload a zip file as bytes to my server. But the server is giving a 404 error. For all the other requests the server is running fine, so don’t know what is going wrong.

I’m passing zip_file = uploaded_file.getvalue() as the parameter for the function that creates and sends the request:

def send_image_zip_file(self, zip_file):
      headers = {'Content-type': 'application/octet-stream'}   
      response = requests.post(self.api, 
        files=[('zip_file',('file.zip', zip_file, 'file/zip'))])
          server_response = response.json()   
      except requests.exceptions.RequestException:

Hi @Tykwer :wave:

A few things to check:

  • Is the URL passed in self.api is correct and properly formatted?
  • Is the file being properly included in the request?
  • Also I think the MIME type for zip files is application/zip instead of file/zip.

Let us know if that fixes it, otherwise we’ll have another look :slight_smile:


Thank you, Charlie.

Yes, the URL is correct.

How can I make sure if the file is properly included in the request? The idea is to send the bytes (preferentially as base64), then reconstruct the zip file once receiving it at the server side.

I corrected the MIME type.

Server is now returning error 415

Hi Charlie,

I fix it. Turns out the issue was coding/encoding. This thread helped.

For small files it works fine. But as I need to send large zip files (1+ GiB), I’m having this problem with Axios now:

AxiosError: Request failed with status code 413

Do you know how can we send large files through streamlit ??
I already changed the maxUploadSize

1 Like

Hey Tykwer,

Glad to hear that changing the encoding worked!

A 413 error means “Payload Too Large,” indicating that the request body size exceeds the server’s maximum allowable size.

Would you be able to compress the files before sending them?


Hi @Charly_Wargnier

Do you know how to compress/uncompress it? I thought the zip was already doing it. One thing that I thought is that the json string might be too large, so it increases the payload. But I don’t know another way to serialize it aiming to decrease the payload.

Another possible issue is that I’m using Ngrok on the server side, so it may have this limitation on the data amount it can receive, but I’m not sure about that.

Zip does compress the file, but with many tools you can control the amount of compression that it does. That might not make much of a difference, but you might give it a try. For example, zip -9 file.zip original_file, the -9 is the maximum compression (which is slower).

Most likely the issue is from the server itself, and has nothing to do with streamlit. I would recommend looking at documention for the server you are using (ngrok or whatever is the underlying server) to figure out if it limits the amount of data you can send, and if it’s possible to increase that amount.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.