2

I have a website where the user can access a video that is saved in my bucket on Google Cloud Storage with the signedUrl, but the video has the Download option:

enter image description here

and I don't want to allow this button, I want the video to be just for preview. How can I do this? I didn't find anything in the GCS documentation (https://googleapis.dev/nodejs/storage/latest/index.html).

I'm using NodeJs for the back end and I'm creating the signedUrl like this:

var expiry = new Date(Date.now() + 120000);
const file = bucket.file(req.file.cloudStorageObject);
const config = {
  action: "read",
  expires: expiry
};

file.getSignedUrl(config, function(err, url) {
  if (err) {
    console.error(err);
    return;
  }

  // The file is now available to read from this URL.
  request(url, function(err, resp) {
    console.log(444444, url);
  });
});
res.send(200);
AndrewL64
  • 15,794
  • 8
  • 47
  • 79
Henrique Ramos
  • 714
  • 8
  • 25
  • Even if you remove the download option if a user wants to download that video I am sure they will find another way by searching the video source/path or maybe even have a browser plug-in that detects videos played/loaded in the browser and offer a download for them. I think the only possible way for you to do this is to create a session/token which expires if it isn't updated after so long but even that is a guess of a solution. – NewToJS Feb 29 '20 at 21:34
  • I am aware that if he wants to download it he downloads it, however I would like to remove the download button to at least make it a bit more difficult. Do you know how I can do this? @NewToJS – Henrique Ramos Feb 29 '20 at 21:47
  • @HenriqueRamos Please provide a link to the page. – AndrewL64 Feb 29 '20 at 21:48
  • @AndrewL64 i make this link for you see: shorturl.at/JV059 – Henrique Ramos Feb 29 '20 at 21:55

2 Answers2

2

You can use the controlsList property of the HTMLMediaElement interface to remove the download button from your video element.

Just use the setAttribute method to add the controlslist attribute with a value of nodownload to your video element after the page loads and it should remove the download option for you.

document.querySelector('video').setAttribute("controlslist", "nodownload");

Check and run the following Code Snippet for a practical example of the above approach:

document.querySelector('video').setAttribute("controlslist", "nodownload");
<video controls="" autoplay="" name="media"><source src="https://storage.googleapis.com/plataforma-redacao/1583013110538y2mate.com%20-%20OZZY%20OSBOURNE%20-%20Under%20The%20Graveyard%20%28Official%20Audio%29_fMAAMfHgO4Q_720p.mp4?GoogleAccessId=plataforma-redacao%40redacao-269717.iam.gserviceaccount.com&amp;Expires=1583025155&amp;Signature=bScPwZkEhJVjt8mEQMT0BeE8CdQLoqPb5CrxLd%2BLUTd%2BF6ypL3eNVe3oGSxiRM4nWpfESlA32PgsrQ417%2FZrWuT%2FxZoeyQmSxW0G4ksZjG%2FNWBnsMGBRP7D6a2nJsuS%2BYy82anismfaBKtKEhTRhF6EehC3YRQD5BqgeJ8Q4yU3u9IeI9WWwr8aeQJUt2PafWiNADGz9rk4hR%2BdWl3SHR5sj9fZf6k8%2BSyW3ZKPsd%2BzGGrX6QhpkKYXCxf%2FioedEClbFriWKYfKhpZGvkSdmYSv9ZHHUD0%2ByjiXRHWZrO8QOvIQd2kUDATC%2B6EARuHk0jcQmapOAkm2S4k6rwwolbg%3D%3D" type="video/mp4"></video>
AndrewL64
  • 15,794
  • 8
  • 47
  • 79
1

That button is not provided by Cloud Storage. It's provided by the browser that's viewing the content. All public download URLs can be downloaded by directly accessing the URL, and there's really no way of stopping that. Anyone who has the URL can always download the content. If you only want to allow playback and stop all direct downloads, Cloud Storage is not the solution you're looking for. You'll need to use some encrypted video streaming service instead.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441