Pete
Pete

Reputation: 7589

Use Google Cloud Storage to Host Audio Files for Streaming but not Downloading

I have a bunch of audio files that I want people to be able to listen to. My website has an audio player so that people can listen to them. My audio player looks something like this (though this is simplified):

<audio>
    <source src="https://storage.googleapis.com/my-bucket/my-file.mp3">
</audio>

The problem is that it would take almost no work for someone to just grab all of those MP3 urls and download the files.

Is there a way that I can make it so that it's only accessible for streaming, but not for downloading?

How do sites like SoundCloud handle this problem?

For example, SoundCloud lets you play people's songs. However, when I look in Firefox's Network tab I see that when playing a single song it's sending many requests to different MP3 files such as:

/media/3831430/3943025/c9OpfFFp3iYQ.128.mp3
/media/3192789/3352448/c9OpfFFp3iYQ.128.mp3
/media/3033128/3192788/c9OpfFFp3iYQ.128.mp3

Does anyone know what type of system they have going on there? Is this a common anti-piracy pattern for MP3 files that I could, perhaps, implement?

Upvotes: 1

Views: 2554

Answers (1)

vizsatiz
vizsatiz

Reputation: 2183

I was hit by the same problem, and I secured my storage bucket from the world by creating a middleware/pass-through service. Now this service has token validation of header and thus wont let your stream until you are authenticated. I used node pipe to achieve this, I hope this help. Here is sample code in js.

const http = require('http');
http.createServer(function(request, response) {
  require('request')
  .get("https://gcpmusicbucket.com/mp3/My-Song-1.mp3")
  .pipe(response); 
})
.listen(3000)

Upvotes: 2

Related Questions