# File upload via serverless function

**URL:** <https://community.hubspot.com/t/file-upload-via-serverless-function/107833>\
**Category:** CMS Development\
**Tags:** enterprise\
**Created:** [May 23, 2024, 10:18am UTC](https://community.hubspot.com/t/file-upload-via-serverless-function/107833 "2024-05-23T10:18:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MHlavacka](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mhlavacka/32/5125_2.png) [@MHlavacka](https://community.hubspot.com/u/MHlavacka)\
**Post date:** [May 23, 2024, 10:18am UTC](https://community.hubspot.com/t/file-upload-via-serverless-function/107833/1 "2024-05-23T10:18:02Z")

</div>

Hi, I need some explanation about how to handle file uploads via serverless functions in HubSpot CMS. Can you help me out?

**What I am trying to do:**

- I have a website made in HubSpot CMS
- This website uses multiple serverless functions which I am using to primarily update data in HubDB.
- Now I need to add file upload functionality to it, too, where I want to store files directly in HubSpot’s File Manager. This is how I imagine it to work:
  - On customer facing website, there will be file selector field and a button
  - When the button is clicked, if the file has been selected, POST request should be sent to my serverless function.
  - This function is supposed to get the file and upload it to HubSpot’s file manager ([Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/api/files/files#endpoint?spec=POST-/files/v3/files))
  - Once uploaded, it should store the link to the file in HubDB and return it back to frontend, too.

**The problem I am facing:**

- To my currently best understanding, the serverless functions ONLY accept application/json Content Type for requests, meaning that I am unable to send binary files there.

**Possible solutions:**

- I can make skip serverless function and make the API request directly to Files API. That will, however, expose my API keys. So it is a no-go.
- I can code custom middleware outside the HubSpot on my own server and send the request there instead of the serverless function. That will, however, mean that I not have two applications to maintain and I want to only have HubSpot without external middleware.

**Question from other user on this topic:**

- [https://community.hubspot.com/t5/CMS-Development/Create-a-file-upload-in-serverless-function/m-p/772122#M33422](https://community.hubspot.com/t5/CMS-Development/Create-a-file-upload-in-serverless-function/m-p/772122#M33422)
  - Is this how it should be done? Even if the file is several hundreads MB video? Is there no limit on how long the json data can be?

**Actual solution:**

- I am currently not aware of any official solution for this. Can you recommend some, please? How should this be solved properly?

Thank you,  
Martin

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [May 24, 2024, 6:11pm UTC](https://community.hubspot.com/t/file-upload-via-serverless-function/107833/2 "2024-05-24T18:11:07Z")

</div>

Hey, @MHlavacka 👋 I believe you have correctly listed out the limitations and a possible solution. There is not a documented way to change or add another Content Type.

We’ll leave this open in case other community members have a suggestion for you.

Best,

Jaycee
