# invoke an external API to send the record's data and the uploaded File (Image)

**URL:** <https://community.hubspot.com/t/invoke-an-external-api-to-send-the-records-data-and-the-uploaded-file-image/121832>\
**Category:** APIs & Integrations\
**Tags:** forms\
**Created:** [December 3, 2024, 10:57pm UTC](https://community.hubspot.com/t/invoke-an-external-api-to-send-the-records-data-and-the-uploaded-file-image/121832 "2024-12-03T22:57:00Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![HemanthKotha](https://avatars.discourse-cdn.com/v4/letter/h/a3d4f5/32.png) [@HemanthKotha](https://community.hubspot.com/u/HemanthKotha)\
**Post date:** [December 5, 2024, 8:23pm UTC](https://community.hubspot.com/t/invoke-an-external-api-to-send-the-records-data-and-the-uploaded-file-image/121832/5 "2024-12-05T20:23:51Z")

</div>

Hi @evaldas Thanks for the solution.  
Here is what I have tried: Reading and encoding a file. It works.

```lia-code-sample
const axios = require('axios'); // For making HTTP requests.

exports.main = async (event, callback) => {

 try {
 // Example: Get contact properties from the event
 const contactId = event.object.objectId;
 const contactEmail = event.inputFields['email'];
 const file = event.inputFields['uploadedFile'];

 const response = await axios.get(file, {
 responseType: 'arraybuffer',
 });
 const base64Image = Buffer.from(response.data, 'binary').toString('base64');

 // Payload to send to the external system
 const payload = {
 id: contactId,
 email: contactEmail,
 filename: "uploaded-image.png", // Replace with desired file name.
 filetype: "image/png", // Replace with the correct MIME type if different.
 content: base64Image, // Base64 encoded content.
 };

 callback({
 outputFields: {
 status: "Success",
 payload: payload,
 },
 });
 } catch (error) {
 console.error("Error posting data: ", error);

 // Return error response
 callback({
 outputFields: {
 status: "Error",
 message: error.message,
 },
 });
 }
};

```

---

_[View the full topic](https://community.hubspot.com/t/invoke-an-external-api-to-send-the-records-data-and-the-uploaded-file-image/121832)._
