File upload via serverless function

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)
    • 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:

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

Hey, @MHlavacka :waving_hand: 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