Using static files in Heroku

Hi @dan_baker ,

I need your help on this issue, I take this paragraph form your detalied explanation about deploying to Heroku:

  1. Use the Whitenoise library. Quick and easy. A few lines of code and you’re serving files in the way you would imagine.

I have a problem to reproduce audio in Heroku, I run an app that converts text into mp3 file, but the issue is to get a way to save the file and then reproduce it in Heroku app.

I can reproduce audio that is stored in the assets folder and also audios from others url location, but can’t find a way to save and read it dynamically.

If I understand correctly you suggest using Whitenoise to solve this issue.

I followed your indication but can’t understand how to save the file into the static/ folder.

Could you provide an example ?

Thanks in advance :grinning:

I found that I did not create the folder static, thats why it didn’t save it.

But now the problem persist, I run the app in my local enviroment and works perfect, but do not work in Heroku :thinking:

I can see that the mp3 files are saved in the Heroku static/ folder but the html.Audio do not play it. :thinking:

Hi Eduardo

Sounds like you are half way there, and you have the mp3 files being generated on Heroku, but you can’t serve them. This is almost certainly because you have not implemented the whitenoise library properly.

assuming you have done the basics like

server = app.server
server.wsgi_app = WhiteNoise(server.wsgi_app, root=‘static/’)

It’s worth mentioning that when Whitenoise is running, HEROKU SEES THE STATIC FOLDER AS ROOT.

This means the path to your mp3 files DO NOT need ‘static’ in them. They should just be ‘blah.mp3’ and not ‘/static/blah.mp3’.

It’s probably something as simple as that, so just play around. Try image files too and just check you can serve them on Heroku. Then Im’ sure your MP3s will work.

Mp3 files may not persist
Also remember that the Heroku file system is ephemeral, so any files created during run time, even your mp3s in static (i’m pretty sure) will disappear after a few days. If this is a problem for you, you will probably need to look at binary storage like Amazon S3 or Microsoft Azure Blob.

Let me know if you get it working!
Dan

1 Like

Hey Danny. You are the Special One, like Mourinho. :joy: :joy:

It Works :tada: :tada: :tada: :star_struck: :star_struck:

And also the temporary permanence of the files instead of been a problem is a solution, because I only need to reproduce paragraph by paragraph mp3 files that are virtually generatad and must be deleted later, that means I do not neeed to be worried if some files are not deleted during the code execution. :grinning: :grinning:

Here is the app, it is a simple Translator for different languages with the option to find word by word definitions:

https://amimedida.herokuapp.com/

You can copy and paste any web page and will be translated paragraph by paragraph.

1 Like