Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to prevent download video

I have a video project on php/laravel framework.
Any user can create an account there and can upload videos there and after few verifications the video will be live, and any user can watch the video. The project is deployed on the google cloud.

Video is being stored on the public folder of the project. I need to prevent download the videos from external resources. Like: copy and paste the url on the browser etc.

Even If I right click on the video player the it shows "Save as" option and it is being stored on the local system. How can I prevent them?

The video must be play into the html video player.

1- Should I go store the videos into cloud storage?  If yes, then is it possible to solve my problem like I have asked above?
2- Or Shall I select any other option like google VOD server or something else.

Thank you.

3 3 1,291
3 REPLIES 3

Hi @vinodjaiswal87 

To prevent the downloading of videos from your PHP/Laravel project hosted on Google Cloud and ensure that they can only be played through the HTML video player, I would suggest storing the Videos in Google Cloud Storage rather than in the public folder of your project.

Let's do the following steps

(1) Create Google Cloud Storage Bucket

(2) Upload Videos to the Bucket

Use gsutil command-line tool to upload your videos to the bucket

 

gsutil cp /path/to/video.mp4 gs://your-bucket-name/.

 

(3) Set Private Object Permissions

Set the videos to be private by default and control access through signed URLs or Cloud Identity and Access Management (IAM) policies.

(4) Generate Signed URLs:

  • Implement a backend service in your PHP/Laravel application that generates signed URLs for accessing the videos.
  • Use the Google Cloud client library for PHP to generate signed URLs with an expiration time.

(5) Integrate Signed URLs with Your Video Player

  • Modify your video player implementation to request a signed URL from your backend service instead of directly pointing to a public video URL.
  • Set the src attribute of your HTML video tag to the signed URL provided by your backend.
  • Code Snippet to Generate Signed URL in PHP:

 

use Google\Cloud\Storage\StorageClient;

function generate_signed_url($bucketName, $objectName, $expiration) {
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $object = $bucket->object($objectName);
    $signedUrl = $object->signedUrl(
        new \DateTime('+1 hour') // Expires in 1 hour
    );

    return $signedUrl;
}

 

I hope that helps 

Regards

Mahmoud

 

 

Thank you @mahmoudrabie ,

Will it prevent to download the videos, if I right click on the video player? It gives option "Save as".

Or Should I go with any DRM solution? LIke: Google Widevine DRM

Hi @vinodjaiswal87,

Trying to stop people from downloading your videos by disabling right-click might work for some, but it's not the best solution. Tech-savvy people can easily find ways around it, leaving your content vulnerable.

For real protection, consider using a Digital Rights Management (DRM) system like Google Widevine DRM, like the one you mentioned. This encrypts your videos so only authorized users can watch them, making it much harder for people to download them illegally. It's like putting a super strong lock on your content instead of just relying on a flimsy one.

You may also review this article - How to prevent video download in Laravel?

Thank you.