So I want to make it a little bit more difficult for users to directly download MP3 files from the server (just from going straight to the URL
of the source). I've been looking around and, from what I've gathered, a good way to go about this is to convert an Audio
object to a use-once Blob
(similar to how YouTube does it).
As an example, something like this:
<!-- directly accessible, unobfuscated url -->
<audio src="www.mywebsite.com/media.mp3"></audio>
Would become:
<!-- visiting the link would lead to a 'your file was not found' page
and the original url is now obfuscated -->
<audio src="blob:http://www.mywebsite.com/6fc4f9d2-035a-4999-b330-96da04c0f6a8"></audio>
At the moment, this is how I'm doing it:
var url = "http://www.mywebsite.com/media.php"; // media.php points to an mp3 file
var audio = null; // just for simplicity sake - i'm not actually doing it like this
if(!audio){
audio = new Audio(url);
} else {
audio.pause();
audio.src = url;
}
Now I was looking at this answer (along with a couple others), but they all either involve using a file selected from an input
or, as this one is, using the file as a Base64
string and converting that to a Blob
, which I can't figure out how to do and imagine to be a somewhat heavy task to do on the client-side.
Essentially, all I need to do is convert the url
to a Blob
that can only be used once in that session (cannot be directly accessed in another tab - just that one time it's being played, for example).
NOTE: I Tagged PHP
as this may also be a server-side issue, feel free to correct that if necessary.