Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
how to access the ReadableStream inside of the body of the Promise response

I have an mp3 file that I am caching as such:

const request = URL_TO_MY_MP3_FILE
caches.open("my-cache").then(cache => {
   cache.add(request);
});

I can see that the mp3 file is being cached in the Application tab: enter image description here

By the way, how do I ensure that file is cached as audio/mp3 and not audio/mpeg?

Later on, I would like to retrieve the mp3 file from cache so I can play it in the browser:

caches.open("my-cache").then(cache => {
     const response = cache.match(request);
     console.log(request, response);
     this.audio = new Audio(response.body);
})

enter image description here

My first question is how to access the ReadableStream inside of the body of the Promise response. Unfortunately, response.body is equal to undefined and I don't understand how to access the mp3 file otherwise.

Secondly, how do I ensure that file is cached as audio/mp3 and not audio/mpeg?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

I found the answer here: How to access the value of a promise?

caches.open("my-cache").then(cache => {
     const response = cache.match(request);
     console.log(request, response);
     response.then(function(result) {
        this.audio = new Audio(response.body);
     }.bind(this), false);
})
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!