Skip to main content

Uploading image files to an attachment field via API


Forum|alt.badge.img+3

I want to add images to an attachment field in an Airtable.  I've read all of the documentation and Community comments but can't seem to find an answer to my problem.

  • I have a publicly accessible link to the image
  • I can call https://api.airtable.com/v0/{baseID}/{tableID}/{recordID} and add an image fine, however, I want to make multiple other calls adding new versions of the image and this call overwrites what is already there but I want to keep the previously uploaded files.  (I understand this is an Update call and that logic makes sense.)
  • Therefore, I believe I should call  https://content.airtable.com/v0/{baseID}/{recordID}/{fieldID}/uploadAttachment  passing in a similarly formatted JSON object, however, I cannot get that to work.  I get something added to the attachment field, however, it is just 1K gibberish file.

    • Here is a copy of what I'm calling:

      curl --location 'https://content.airtable.com/v0/{baseID}/{recordID}/{fieldID}/uploadAttachment' \
      --header 'Authorization: Bearer {accessToken}' \
      --header 'Content-Type: application/json' \
      --header 'Cookie: {cookie stuff}' \
      --data '{
          "contentType": "image/png",
          "file": "{publicly accessible URL to image}",
          "filename": "Content_Hub_Portraitv2.png"
      }'

    • Any help would be appreciated.

Thanks much.

 

TheTimeSavingCo
Forum|alt.badge.img+28

The 'uploadAttachment' API expects the actual file, not a URL to the file I'm afraid; the documentation mentions that it's done via the file bytes directly

As such, you're going to need to retrieve the image first, convert that, and then use that endpoint

As an alternative, you could also try retrieving the record first, append the new file, then do a PATCH?


ScottWorld
Forum|alt.badge.img+33

@KevinKearns 

You can use public URLs to upload attachments to a record, but you need to do it through the update record API call (or new record call).

Airtable’s new API documentation is extremely confusing, so I would recommend looking at Airtable’s old API documentation, which is PERSONALLY CUSTOMIZED FOR YOUR BASES! 

Go to this page, scroll down, choose your base, and the API documentation’s CURL code will be customized for your bases & fields: https://airtable.com/developers/web/api/introduction

- ScottWorld, Expert Airtable Consultant


TheTimeSavingCo
Forum|alt.badge.img+28
ScottWorld wrote:

@KevinKearns 

You can use public URLs to upload attachments to a record, but you need to do it through the update record API call (or new record call).

Airtable’s new API documentation is extremely confusing, so I would recommend looking at Airtable’s old API documentation, which is PERSONALLY CUSTOMIZED FOR YOUR BASES! 

Go to this page, scroll down, choose your base, and the API documentation’s CURL code will be customized for your bases & fields: https://airtable.com/developers/web/api/introduction

- ScottWorld, Expert Airtable Consultant


@ScottWorld  Hmm, you mentioned Airtable's 'new' API documentation being confusing and recommended the old ones.  What's new about them?

Do you have a link or something specific I can check out? As far as I can tell, nothing's changed!


ScottWorld
Forum|alt.badge.img+33

I just gave you the instructions above on how to access the old documentation.

And yes, the documentation went through a major overhaul a few years ago, which everybody has found incredibly confusing, particularly compared to the clarity and personalization of the old documentation.

- ScottWorld, Expert Airtable Consultant 


Forum|alt.badge.img+3
  • New Participant
  • December 19, 2024

I was able to update the attachment field using the information that @ScottWorld provided.  @TheTimeSavingCo I'd still like to try to use the UPLOADATTACHMENT option  but I don't know what you mean by "via the FILE BYTES directly" reference?  I'm hoping this option does not require putting my files on a publicly accessible URL site just to import them.  Thanks for your help.


TheTimeSavingCo
Forum|alt.badge.img+28
ScottWorld wrote:

I just gave you the instructions above on how to access the old documentation.

And yes, the documentation went through a major overhaul a few years ago, which everybody has found incredibly confusing, particularly compared to the clarity and personalization of the old documentation.

- ScottWorld, Expert Airtable Consultant 


@ScottWorld 

Yeap, I have access to that and that's the one I linked to!  Could you provide a link to this new documentation you're talking about?

---
@KevinKearnsYou'd basically need to retrieve file from the URL and then send the actual file into the endpoint.  Given that you've already got it working I don't think this is worth the effort though


ScottWorld
Forum|alt.badge.img+33

No, that isn’t what you linked to. The old & superior documentation is the custom interactive documentation that changes itself based on what base you choose.


TheTimeSavingCo
Forum|alt.badge.img+28
ScottWorld wrote:

No, that isn’t what you linked to. The old & superior documentation is the custom interactive documentation that changes itself based on what base you choose.


Ah I see, you're referring to the 'Upload Attachment' endpoint documentation I linked to! https://airtable.com/developers/web/api/upload-attachment

That isn't referenced in the interactive documentation as far as I can tell!


TheTimeSavingCo
Forum|alt.badge.img+28
TheTimeSavingCo wrote:

Ah I see, you're referring to the 'Upload Attachment' endpoint documentation I linked to! https://airtable.com/developers/web/api/upload-attachment

That isn't referenced in the interactive documentation as far as I can tell!


Hmm, I view the interactive docs as a subset of the overall documentation.  The non-interactive docs (screenshot below) contain plenty of information that the interactive docs doesn't e.g. auth levels, scopes, path parameters etc, and so only using the interactive docs might be detrimental

If you could provide a link to the upload attachment API in the interactive docs that'd be super helpful though; they're definitely easier to consume like you said!


ScottWorld
Forum|alt.badge.img+33

Yeah, that is the highly unfortunate thing about Airtable's API Documentation team. When they came out with the new API documentation, they stopped updating the old interactive documentation, so like you said, the old documentation is only a subset of the API calls. It's really an unfortunate situation, all the way around. We should send them feature requests to ask them to keep updating the old interactive documentation.


Reply