Help

Problem uploading attachments from public URL

Topic Labels: Automations
252 3
cancel
Showing results for 
Search instead for 
Did you mean: 
mariana_rato
4 - Data Explorer
4 - Data Explorer

Hey everyone. I have a public URL link that I'm trying to use to upload to an airtable attachment field with airtable scripting. This is my code (the URL is obtained from an API call response): 

"
let existingAttachments = recordA.getCellValue('attachmentsA');
let updatedAttachments = existingAttachments ? [...existingAttachments, { filename: fileName, url: responseData.pdf }] : [{ filename: fileName, url: responseData.pdf }];
await tableA.updateRecordAsync(recordId, { 'attachmentsA': updatedAttachments});
"
My issue is that sometimes this works and sometimes it doesn't, without any aparent pattern, and I know that the URL from my API call is always correct. When I go to the airtable record and see the activity it shows me that the attachment was uploaded and deleted, but I don't delete it in my code.
Does anyone know how to solve this problem? Thank you! 
3 Replies 3

What are the values for fileName and responseData.pdf? (Is responseData an object with a property of pdf that contains the actual url?)

Usually when the record history shows an attachment uploaded and immediately deleted it is because Airtable was not able to download the file. Here are some common reasons.

- The url provided is not a public url. If the url requires the user to be logged in, the upload will not work. To test if the url is a public url, try using an incognito or private window of the web browser.

- The url is a "viewer" url that opens a webpage that displays the file in a viewer, versus directly showing the raw file.

- The url is invalid. Usually you can tell if this is the case because you don't get the file if you put the url in a web browser.

Incorrect file types could be an issue too; the user in this thread tried to upload files with URLs ending with .jpg and those would delete themselves, turns out they were actually .avif files instead which I think was causing the issue

Thank you for your response! "responseData" is a JSON object, with one of the parameters being "pdf", which contains an url of the type "https://abc?fileName=defg%49.pdf" (this is not a valid one, just an example to show you the format, and I don't use the fileName given in the link, I define it as "test.pfd"). When I use this link in my web browser it downloads the pdf and it always works in incognito/private window mode also, so I know that my pdf is not a problem, because I can always access it. Do you have any other possible solutions? Because the link is always of the same type, obtained in the same way, but sometimes it's upload to airtable works sometimes it doesn't.