1

In my Lumen app I'm getting audio file from external Lumen service and saving it in Storage.

$tempname = tempnam(sys_get_temp_dir(), 'response').'.mp3';

Http::sink($tempname)->get(myExternalResourceUrl);

Storage::putFile('/public', new File($tempname));
$path = Storage::path($tempname);

return response()->download($path, 'myAudio.mp3', ['Content-Type' => 'audio/mp3']);

Also I've checked my saved files in storage and they don't have any problems. I think I cannot use here just link to my file in storage because I should delete it after receiving in frontend.

On my frondent (vue.js) I've tried to do this:

<audio>
  <source :src="audio.resource">
</audio>

promiseToDownload.then(data => {
   const url = window.URL.createObjectURL(new Blob([data]), {type: 'audio/mp3'});

   this.audio.resource = url;
});

I have no errors, but my audio is simply doesn't work. It shows only zeroes on audio time. Begging for help

I've tried to replace response()->download($path, 'myAudio.mp3', ['Content-Type' => 'audio/mp3']) with Storage::download($tempname); but it also doesn't work.

2
  • On the frontend, why not just reference your Laravel script URL as the audio src? Commented Aug 9, 2023 at 17:51
  • @Brad it's because I should watch when my audio is downloaded and delete it from storage then Commented Aug 10, 2023 at 6:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.