Help

URL to Attachment

Topic Labels: Scripting extentions
29578 48
cancel
Showing results for 
Search instead for 
Did you mean: 
Aaron_Phoenix
5 - Automation Enthusiast
5 - Automation Enthusiast

I have registration forms that collect a digital signature. It imports into airtable as a url, like this: (https://s3.amazonaws.com/files.formstack.com/uploads/3669579/85172110/582992994/signature_85172110.p...)

Can someone help me with a script that would convert this to an image attachment?

48 Replies 48
espressivo
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi! I have sooo enjoyed this script for images. But I have a PDF automatic download link like this: https://www.teacherspayteachers.com/Preview/Noun-Sort-Cut-and-Paste-083291900-1381063936?fn=valentin...

That is NOT pulling the PDF correctly. Any ideas?

One idea - that URL is not publicly accessible, a requirement of Airtable attachments.

espressivo
5 - Automation Enthusiast
5 - Automation Enthusiast

Ah, makes sense. Ok, thanks!

espressivo
5 - Automation Enthusiast
5 - Automation Enthusiast

Viewers do note make it possible for a GET request to access the file. Viewers are for humans; Airtable’s attachment system is a machine.

espressivo
5 - Automation Enthusiast
5 - Automation Enthusiast

Ha, yeah, I know. I want the impossible :slightly_smiling_face:

The viewer you shared is an HTML proxy for viewing what appears to be a PDF document. Someone needs to tell you how to look at the PDF without going through that proxy. Then, and only then, will Airtable be able to ingest the documents.

So, i’ve been following along on this, trying to apply it to my own table.

Could you possibly post the entire script, start to finish, that you were able to execute fully? Then I might be able to more clearly see where my error is…!

Joshua_Green
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi - This script works great for one URL to attachment , but is it possible to make it work with several URLs? I have 7 columns of URL images (some records do not have all 7 filled), and tried to get it to do more than one column but have been unsuccessful. (My scripting levels are not great but I usually can get there in the end after a lot of trial and error, but I’ve come to a standstill on this attempt. )

Thanks

Marty_McCoy
6 - Interface Innovator
6 - Interface Innovator

image

@Stephen_Suen @Kasra, this is all working great for me except for one component: My image in the Attachment field doesn’t display as it should. See screenshot above. The link I am trying to load goes to a Google Drive image file. The permissions are set so anyone with the link can view.

How can I modify the code or the link so it correctly imports the Google Drive link as an attachment?

The link follows this pattern:

https://drive.google.com/file/d/file_id/view?usp=sharing

Here is the code:

let submissionsTable = base.getTable('Table 10');
let urlField = submissionsTable.getField('Attachment Source URL');
let attachmentField = submissionsTable.getField('Attachment');

let submissionsQuery = await submissionsTable.selectRecordsAsync();
let updates = [];
for (let record of submissionsQuery.records) {
    let url = record.getCellValue(urlField);
    let attachments = record.getCellValue(attachmentField);

    // If this record already has an attachment, skip it.
    if (attachments !== null) {
        continue;
    }

    // Otherwise, attach the image at the URL.
    updates.push({
        id: record.id,
        fields: {
            [attachmentField.id]: [{url: url}]
        }
    });
}

// Update records in batches of 50.
while (updates.length > 0) {
    await submissionsTable.updateRecordsAsync(updates.slice(0, 50));
    updates = updates.slice(50);
}