I’m working on a React project with Airtable and I’m having trouble showing an image. My logo file is in the same folder as my main JavaScript file but it’s not showing up. I’ve tried a few ways to link the image but nothing seems to work. Here’s what I’ve attempted:
I’ve dealt with this issue before in Airtable Blocks. The problem is that Airtable’s runtime environment doesn’t handle local file paths like a typical web server would. Instead, you need to use Airtable’s own asset handling system.
Here’s what I’d suggest:
Upload your image to Airtable as an attachment in a dedicated table.
Fetch the attachment URL using Airtable’s API.
Use that URL in your img tag.
Here’s a quick example of how you might implement this:
I’ve encountered similar issues when working with React and Airtable. The problem likely stems from how React handles static assets. Here’s what worked for me:
Try moving your image to a ‘public’ folder at the root of your project. Then, reference it using the public URL path:
<img src={'/myicon.png'} alt='My Icon' />
If that doesn’t work, you might need to use Airtable’s asset handling. Upload the image to Airtable, then fetch it using their API. Something like:
const [iconUrl, setIconUrl] = useState('');
useEffect(() => {
// Fetch the attachment URL from your Airtable base
const fetchIcon = async () => {
const record = await base.getTable('YourTable').getRecord('RecordId');
setIconUrl(record.getCellValue('IconField')[0].url);
};
fetchIcon();
}, []);
// Then in your JSX
<img src={iconUrl} alt='My Icon' />
This approach has been more reliable for me when working with Airtable and React.