Upload file via lambda function to IPFS

I’m trying use Netlify function as a proxy for uploading files to IPFS server.
My function looks like this

exports.handler = async (event, context) => {
  const BASE_URL = 'https://api.pinata.cloud/pinning/pinFileToIPFS';
  const formData = new FormData();
  formData.append('file', event.body);

  try {
    const { status, data } = await axios.post(BASE_URL, formData, {
      withCredentials: true,
      maxContentLength: 'Infinity', //this is needed to prevent axios from erroring out with large files
      maxBodyLength: 'Infinity',
      headers: {
        'Content-Type': 'multipart/form-data',
        pinata_api_key: process.env.VUE_APP_PINATA_API_KEY,
        pinata_secret_api_key: process.env.VUE_APP_PINATA_SECRET_API_KEY
    console.log('[PINATA] Pin Image', status, data);
      return {
        statusCode: status,
        body: JSON.stringify(data),

  } catch (e) {
    console.log('[UNABLE TO POST]', e.message)
    return {
      statusCode: 400,
      body: JSON.stringify(event, null, 2),

Using the same function fronted it work, however I’ll get 400 error on the lambda

Hey there, @vikiival :wave:

Welcome to the Netlify Forums :netliconfetti: Sorry to hear you are having some difficulty here. Can you share your Netlify site name with us?

Also, have you poked around some of our other threads? This thread on 400 errors and this thread referencing IPFS might be good starting points.