Re: How can i get an attachment from a table and send it in a PUT call?

1038 0
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

So im trying to upload videos to youtube via an airtable database. Currently my application sends video files to a database in airtable and I want to build a script that sends the attachment to a specific URL. Im having trouble figuring out the script to query the URL and then how do I format it correctly so the PUT call will accept it. 

Ive provided a screenshot of what my simple database looks like. I need to have the attachment in the "Videos" field be sent in the "<file contents here>" portion of the follow script:


var myHeaders = new Headers();

var file = "<file contents here>";

var requestOptions = {
  method: 'PUT',
  headers: myHeaders,
  body: file,
  redirect: 'follow'
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error'error));
If anyone could help me on this one it would be greatly appreciated as I'm very new to airtable and not to familiar with querying! Thanks! 
1 Reply 1
4 - Data Explorer
4 - Data Explorer

I tried to make some sample code and idk if this will help but its the start I have

// Airtable Script to Find a File in a Table and Upload it using Fetch API

let table = base.getTable("upload");
let query = await table.selectRecordsAsync();

// Find the file record in the "upload" table with the video file attachment
let record = query.records.find(record => record.getCellValue("Video") !== null);

// Check if a file record was found
if (record) {
// Get the file contents from the attachment field
let attachment = record.getCellValue("Video");
let url = attachment[0].url;

// Set the headers and request options for the fetch API
let myHeaders = new Headers();
myHeaders.append("Content-Type", "video/mp4");

let requestOptions = {
method: 'PUT',
headers: myHeaders,
body: await fetch(url).then(response => response.blob()),
redirect: 'follow'

// Make the fetch request to upload the video file to YouTube
fetch("", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
else {
console.log("No file record found in the 'upload' table with a video attachment.");