File API return "Internal error" when upload a 4 mb pdf

Hi everyone,

I’m trying to upload a file to HubSpot File Manager using the Files API: Here is my endpoint:

POST https://api.hubapi.com/files/v3/files

When I upload a file smaller than 1MB, everything works fine. For example, here’s a successful request/response:

Once we receive a successful response, we can add the file ID to the record.

However, when I try to upload a larger file (e.g., a 4.6MB PDF), the request fails with an error:

My Questions:

Is there a documented file size limit for this endpoint?
Is there a different method required for uploading files larger than 1MB?

Has anyone else run into this limitation, and how did you solve it?

Thanks in advance for your help!

Aby

Hi @abbyxia

I checked your issue and I’m not sure where the request format you used came from. According to the official documentation (Upload file – HubSpot Docs), you should be using multipart/form-data.

Currently, you’re sending raw JSON data, which oddly seems to work in some cases. Maybe due to an older specification that I might have missed.

Try with the following format, which follows the official API reference:

curl --request POST \
--url https://api.hubapi.com/files/v3/files \
--header ‘Authorization: Bearer <token>’ \
--header ‘Content-Type: multipart/form-data’ \
--form ‘folderId=<string>’ \
--form ‘folderPath=<string>’ \
--form ‘fileName=<string>’ \
--form ‘charsetHunch=<string>’ \
--form ‘options=<string>’ \
--form file=@example-file

This format should be the correct and supported way to upload files.
Let me know, if it works this way :grinning_face_with_smiling_eyes:

Hi @d-lupo, thanks for your support.

I attempted to upload a file using a serverless function with the "multipart/form-data" content type, but the request returned a 415 Unsupported Media Type error.

I also trie d to upload a file in the API developer tools, but got the server error again.

Any idea what might be going wrong?

thanks

Abby

Hi Abby,
I tested it myself, and everything seems to be working seamlessly.


The 415 error indicates that there’s still an issue with the data format. Please make sure you’ve included the Content-Type: multipart/form-data header in your request.


Hope that helps :slightly_smiling_face:
Dennis

HI there,

The issue here is the file is being sent to a serverless function to upload. Serverless function payloads are limited to 6MB (undocumented as far as I can tell).
If you were to upload a document directly via the files API you won’t hit that limit - documented file upload limits apply (e.g. via postman).
You cannot upload directly to the files API from a browser as the endpoint requires a secret which should not be stored on the client.
The options are:
- Sending the document as a field in a form (in this case it wont work as we need the files ID),
- or; sending the upload request from a proxy service, which in turn uploads the file via the files API as per usual.

Regards,

Jonathan