Help

Re: Script to POST a file

Solved
Jump to Solution
1275 2
cancel
Showing results for 
Search instead for 
Did you mean: 
auekk2787
7 - App Architect
7 - App Architect

I'm trying to script a POST request to the Covve API to parse business cards. Their technical support says "the API does not support passing the file via URL. It only accepts uploading the file itself directly."

Is there a way to do this through Airtable, using the expiring URL? This is the relevant part:

const myHeaders = new Headers();
myHeaders.append("Authorization", apiKey);
myHeaders.append("Content-Type", "multipart/form-data");

const formdata = new FormData();
formdata.append("file", photoURL);

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: formdata,
  redirect: "follow"
};

let postResponse = await remoteFetchAsync(apiUrl, requestOptions);

 

1 Solution

Accepted Solutions

I figured it out. Added this step:

let response = await fetch(photoURL);
let fileBlob = await response.blob();

const formdata = new FormData();
formdata.append("file", fileBlob);

 Our company doesn't allow integration like Make and won't approve consultants. This is my progress in learning Javascript. 

See Solution in Thread

5 Replies 5

Have you tried using fetch() to get the file/blob from the URL and then passing the result as your file?

I'm not too familiar with scripting. How would you do that?

ScottWorld
18 - Pluto
18 - Pluto

Alternatively, if you would like to do this in a low-code way that doesn’t require scripting, you can always do this by using Make’s HTTP modules.

You can use the “Get A File” module to download the Airtable file, and then use the “Make a Request” module to send your POST API request.

Below is a screenshot of how this could look in Make.

If you’ve never used Make before, I’ve assembled a bunch of Make training resources in this thread.

For example, here is how you would instantly trigger a Make automation from Airtable by using a custom webhook.

I also give live demonstrations of how to use Make in many of my Airtable podcast appearances here.

For example, in this video, I show how to work with Airtable attachment arrays in Make.

.Hope this helps!

— ScottWorld, Expert Airtable Consultant

IMG_0509.jpeg


@auekk2787 wrote:

I'm not too familiar with scripting. How would you do that?


You are already using a version of fetch() in your existing script (remoteFetchAsync). Because attachment urls don't have any CORS restrictions, you can use regular fetch() with the url instead of remoteFetchAsync. You can read more about the difference between the two here

What is your scripting background? Depending on how familiar you are with writing your own scripts, you might want to look for a non-scripting option, hire someone to write the script for you, or learn more about JavaScript.

I figured it out. Added this step:

let response = await fetch(photoURL);
let fileBlob = await response.blob();

const formdata = new FormData();
formdata.append("file", fileBlob);

 Our company doesn't allow integration like Make and won't approve consultants. This is my progress in learning Javascript.