Hello,
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