Help

Download attachments and keeping the original file name

1867 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Francoloco23
5 - Automation Enthusiast
5 - Automation Enthusiast

Good day,

I would like to download attachments via a link keeping the original file name. I managed so far to upload a document with the correct file name but the issue is that when downloading in another page it becomes a new generic names for all files

Do any of you know a solution to this? This is currently being integrated with Softr.

Thanks

1 Reply 1
subinbabu
5 - Automation Enthusiast
5 - Automation Enthusiast

One solution to this is to use a service like Cloudinary to host the files, and then use their API to generate a download link with the original file name. This way, when the link is clicked, the file will be downloaded with the original file name.

Another solution is to use a server-side script that retrieves the file from Airtable and sends it back to the client with the original file name as the attachment name. This can be implemented using a language like PHP, Python, etc.

I am familiar with PHP, so I have included a sample. Please check:

 

<?php
//Airtable API Key and Base ID
$api_key = "YOUR_API_KEY";
$base_id = "YOUR_BASE_ID";

//Attachment ID
$attachment_id = "YOUR_ATTACHMENT_ID";

//Get the attachment from Airtable using the API
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.airtable.com/v0/$base_id/attachments/$attachment_id",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer $api_key"
  ),
));
$response = curl_exec($curl);
curl_close($curl);

//Decode the JSON response
$data = json_decode($response, true);

//Get the original file name
$file_name = $data["filename"];

//Get the URL of the attachment
$url = $data["url"];

//Download the attachment
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename='$file_name'");
readfile($url);
exit();

 

You can also use the Softr integration to keep the original file name when downloading attachments via a link. They have a built-in feature for this; you may need to check their support documentation for more information on how to use it.

It's important to note that the solution will depend on the specifics of your integration with Softr and the technology you are using.

Thank you 🙂