I need to allow users to upload CSV files to anvil. Then the server will modify them & they will get a CSV response. I am able to upload & parse files but am stuck on the response.
I have gotten to the point where I am returning a text/plain BlobMedia object from the server to the front end. How do I make it automatically download? Or how to I expose it via button/link/etc?
If the BlobMedia is stored in a Data Table, its url property is a URL from which it can be downloaded. So you can set the url property of a Link to the url property of your BlobMedia, and clicking the Link will download the media.
If the BlobMedia is ‘anonymous’ (not stored permanently anywhere), you can still set the url of a Link object to the Media object itself to allow downloading it:
m = BlobMedia('text/plain', 'Hello, world!', name='hello.txt')
c = Link(text='Open text document', url=m)
Thank you Shaun. Can you clarify which of these steps happen on the front end or server side? If I have a CSV file on the server module, how would I get it to the UI?
I haven’t tried, but you might be able to create a link that links to the object following Shaun’s instructions, then start the download by calling its click event from your code to simulate the user clicking on it?