I understand that Heroku dynos are ephemeral and files cannot be stored between requests. I have a Flask app that should get an MP3 from Spotify, pass it to LibROSA for analysis, then return a visualization.
I have a script that works locally to download the file with urllib.urlopen
, save it to a file, then load that file with librosa.load
. However, I can't seem to load the file from the filesystem on Heroku. How can I load the downloaded file when I don't control the filesystem?
song_url = "https://p.scdn.co/mp3-preview/8e29d103eba74b5cef8600722fff3c491e37fc9a.mp3"
sample_30s = urlopen(song_url)
mp3_path = os.path.join(os.path.dirname(__file__), 'static/data/temp.mp3')
output = open(mp3_path, 'wb')
output.write(sample_30s.read())
y, sr = librosa.load(mp3_filepath)