Help

API: Uploaded attachment types are wrong

Topic Labels: API
Solved
Jump to Solution
10926 20
cancel
Showing results for 
Search instead for 
Did you mean: 
Jed_Davidow
6 - Interface Innovator
6 - Interface Innovator

I have successfully gotten airtable to upload a PNG and a PDF from Dropbox.

But when airtable processes the file, the type is listed as text/html

If I include a type field, I get an error:

{
	"fields": {
		"Type": "Test",
		"Comment": "",
		"Attachments": [
			{
				"url": "https://www.dropbox.com/s/XXXXXXX/robots.png?dl=1",
				"type": "image/png"
			}
		],
		"User": "",
		"Part": [
			"recFI6JhdkwTCeB9q"
		]
	}
}

And I receive this:

{
	"error": {
		"type": "INVALID_ATTACHMENT_OBJECT",
		"message": "Invalid attachment object for field Attachments: {\n  \"url\": \"https://www.dropbox.com/s/XXXXXXXX/robots.png?dl=1\",\n  \"type\": \"image/png\"\n}"
	}
}

But if i just strio out the “type” there is no error, just the type is wrong.

1 Solution

Accepted Solutions

You’re welcome! Glad I could help! :slightly_smiling_face:

To address your other question:

No, the ?dl=1 parameter doesn’t break the file upload to Airtable. You could remove that parameter altogether and your upload to Airtable still wouldn’t work.

The reason it isn’t working is because you’re using Dropbox’s share link that starts with https://www.dropbox.com

That share link doesn’t actually give you the link to the file itself. It is giving you a link to a Dropbox webpage that has the file embedded in it. If you go to your link in a web browser, you will see that you are not taken to the file itself.

In order to extract the actual file from that webpage, you would need to change the beginning of your share link to https://dl.dropbox.com

That will extract the file itself, and you can also see the difference if you go to that URL in your web browser.

See Solution in Thread

20 Replies 20

Attachments accept a URL parameter and an optional filename parameter. There is no type parameter.

You can find this information in the Airtable REST API documentation.

Cresting a new attachment involves only a url and an optional file name. However, the read value of an attachment field does include a file type.

It could be that Airtable is having a hard time determining the file type from the url because your url has query parameters and does not end in a file name. If you include the file name in the value you send to Airtable, Airtable may have more success in determining the file type.

Ah, Thank you. I was using the custom api page for my base to get started,bdidnt think to check the actual documentation to see if the parameter was valid as an input.

Ah! Got it, the dl=1 param breaks the parse for the file extension. I’ll try out the filename param later.

Is there a way to update the type manually? Right now it’s just pdfs and pngs, but we will probably upload binaries and various txt formats.

You’re welcome! Glad I could help! :slightly_smiling_face:

To address your other question:

No, the ?dl=1 parameter doesn’t break the file upload to Airtable. You could remove that parameter altogether and your upload to Airtable still wouldn’t work.

The reason it isn’t working is because you’re using Dropbox’s share link that starts with https://www.dropbox.com

That share link doesn’t actually give you the link to the file itself. It is giving you a link to a Dropbox webpage that has the file embedded in it. If you go to your link in a web browser, you will see that you are not taken to the file itself.

In order to extract the actual file from that webpage, you would need to change the beginning of your share link to https://dl.dropbox.com

That will extract the file itself, and you can also see the difference if you go to that URL in your web browser.

That was it! using “filename”:“robots.png” did not work (came up as application/binary).

Now, I need to figure out from the dropbox API how to get that link and not the www link.

I don’t know if the Dropbox API gives the ability to retrieve that link, so you might need to work out some other methodology of changing the URL to the proper download URL.

You could easily do this with a formula field in Airtable (use the “substitute” function to replace “www” with “dl”).

You could also easily do this with a Javascript.

On my end, I don’t actually know Javascript, so I handle these sorts of automations using Make.com, where they give you the code for how to do this substitution at the very bottom of this page. (It’s not letting me give you the link to the exact part of the page, so just scroll all the way to the bottom.)

In other words, I have Make.com handle the entire process for me — I have Make grab the file from Dropbox, change the URL to the proper download URL, and then upload that file to Airtable.

It does.

String url = meta.getUrl();