Is it possible to upload images to 'Attachments' field-type through Airtable API with PHP?

Hi! :wave:
I am an intermediate-level Airtable user, and using it since 2yrs. Now I have started learning PHP, and I want to integrate the Airtable API with it.

So, I want to build a simple webpage (in PHP), in which the -

  • user clicks the ‘Browse Image’ button, & picks an image from his phone’s storage.
  • After picking, the image would be compressed with some other compressing tool.
  • The compressed image would replace the previous image in the ‘Attachments’ column, specified row no. (Ex. flow : Replace the current image in the ‘Attachments’ column of row #4 with the new compressed image).

Is this possible to do? If yes, can you refer any Docs/Links which might help me?

Any help is appreciated :slight_smile:
Thanks!

@Kartik, yes, this is possible.

Here are a few clues.

  • The Airtable API can upload any images that are publicly addressable. The URL for the image being uploaded must Be openly accessible to Airtable.

  • You PHP app must host the image in a location where Airtable can access it when you add the image to the attachment field. Airtable does the actual upload behind the scenes when you update the attachment field URL.

  • The Airtable API documentation is all you need to update the attachment field with a new image source.

  • PHP is fully able to POST to Airtable via the API using its form actions or you can utilize any of the native JavaScript POST methods as well as the various Airtable SDKs.

1 Like

Hi, @Bill.French!
Many thanks for the reply! You’ve solved 75% of my problem! :smiley_cat:


So, what if I delete my URL-hosted image after it’s uploaded to Airtable?

More clearly,

  • I would host the image to my website first.
  • Then give the image’s direct URL to Airtable API to upload.
  • After the Airtable API returns a success response, (it means the image is uploaded to Airtable) I would delete my hosted image.

Thanks! :slight_smile:

Indeed, but there’s a flaw in this expectation. Once you complete the post to hand over the URL for Airtable to do its “upload”, which is really the act of making a copy via URL, Airtable needs some time to make the copy. This can take a few seconds or minutes depending on the connection, the size of the file, and the relative business of Airtable itself.

You’ll need to create a sleep-gap in your process to ensure Airtable has had enough time to create the image copy and unfortunately, there’s no call-back to inform you of this. Furthermore, there’s no [obvious] way of testing the field to see if the upload is complete. Or is there? :wink:

The way I test to see if an attachment field has a copy of the image is to test for the existence of large or small thumbnail images in the attachment collection. If you request the attachment field and there are thumbnails, the process likely completed. This is almost certainly validation, but there are cases where Airtable is unable to make thumbnails for unknown reasons.

That said, there’s no way to solve your case 100%, but I may have gotten you to 99.5%, eh?