"View as link or image" to download the URL file rather then navigate to it?

I've got a field in one of my tables that I can use as part of a URL. I've used "View as a link or image" settings on the table visualisation to set this up and it references the correct file.

I want to be able to download the file referenced by the URL rather than open it in the browser. I can't figure out how to do this in Metabase. I think the link html needs to include the download="filename.txt" attribute in order for this to work.

I've tried using dashboard click behaviour for this too but no success there either.

I'm happy to open a new feature request in Github for a toggle option for this, but thought I'd check if anyone's got a work around first.

For context the URL that I'm building is actually a data url not a physical file, but from my testing it doesn't seem to matter, if I can get the download="filename.txt" attribute on the <a> element it works.

Any ideas?

Hi @notrom
There's currently no such behavior. You could proxy the request, where you apply download headers.
Or alternatively right-click and select "Save link as ...", which is available in most browsers.

"Save link as" works, can't believe I missed that. Thanks.

I might look into the proxy option, but for now the "save link as" will suffice. Cheers.

Thanks again. I've taken the path of least resistance and just created a little bookmarklet that when clicked looks for links with my data URL media type (text/tr5) and adds a download attribute to the a elements.

I had to add the "download=filename" to the middle of my data url so it strips that out too. This means the bookmarklet works on both dashboards and questions. I haven't yet check about public questions

For reference:

javascript:(() => {
	var items = document.querySelectorAll('a[href*="data:text/tr5,"]');
	for (let index = 0; index < items.length; index++) {
		var item = items[index];
		var segments = item.href.split("|");
		if (segments.length === 3 && segments[1].startsWith("download=")) {
			var dlattr = segments[1].replace("download=", "");
			item.href = segments[0]+segments[2];
			item.setAttribute("download", dlattr + '.tr5');
1 Like