1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const Airtable = require("airtable");
export default async function saveToAirtable(videoName, videoDescription, videoCover, videoFile, clientLogo) {
// Set up your Airtable API key and base ID
const API_KEY = "patrq3goiFF1u09Dz.b435affff5fb534b9d5c76e2544ddf88612d6a19aebaec5c14f9434b0d10d2e6";
const BASE_ID = "appoxM2jYcSNhc5OX";
const TABLE_NAME = "videos_from_ssa";
// Initialize Airtable with your API key
Airtable.configure({ apiKey: API_KEY });
const base = Airtable.base(BASE_ID);
try {
// Prepare the data to be saved in Airtable
const fields = {
"ssa-video-videoName": videoName,
"ssa-video-videoDescription": videoDescription,
"ssa-video-videoCover": [
{ url: videoCover }, // assuming videoCover is a URL to the uploaded file
],
"ssa-video-clientLogo": [
{ url: clientLogo }, // assuming clientLogo is a URL to the uploaded file
],
"ssa-video-videoFile": [
{ url: videoFile }, // assuming videoFile is a URL to the uploaded file
],
"ssa-video-createdDate": new Date().toISOString(),
};
// Create a new record in Airtable
await base(TABLE_NAME).create([{ fields }]);
return { success: true, message: "Record saved successfully." };
} catch (error) {
console.error("Error saving to Airtable:", error);
return { success: false, message: "Failed to save record." };
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 26, 2024