0
votes

I created a LAMP Stack site, and I am hosting it on a Google Cloud Compute Engine VM instance. More specifically, it is a video sharing site, and the videos are currently uploaded and saved to the instance itself.

I was wondering, how can I upload and retrieve videos from Google Cloud Storage instead? Can someone point me to the right direction?

Thanks

1
Howdy ... welcome to Stackoverflow. The area you want to study is Firebase Cloud Storage ... firebase.google.com/docs/storage ... this is the mobile/web interface and APIs for a lot of function. Firebase Cloud Storage is mapped to Google Cloud Storage. - Kolban
@Kolban thank you so much, quick question, my vm instance is able to upload and store videos and then play back on my site. With the help of phpmyadmin's database im able to retrieve the videos and play them using ffmpeg. Why shouldnt I just add more disk space and use my vm instance only to host videos for my video on demand site? - yiby32
You can store your videos on the VM. You will pay a higher cost to do this plus you have to manage backups. The correct design stores the video files on Cloud Storage. The users play (download) the videos directly from Cloud Storage which saves you money, improves performance and offers improved storage reliability. I would also look into a CDN to improve the user experience. - John Hanley
@JohnHanley ohh ok that makes alot of sense. The way I have it set up right now is ffmpeg is my player and needs a directory of where the video is to play it. When I upload to google cloud storage there isnt a directory ffmpeg can refer to. I have been trying to search for ways to do this but im stuck here - yiby32
OK, that is a different application. I thought you were trying to deliver video to users. In your case you are processing uploaded videos that are stored on your VM. That needs to be done on the VM (or using an external service that supports Cloud Storage). Then you can upload the processed videos to Cloud Storage. There are tools such as gsutil and Google SDKs that can copy the video files once processing is complete. - John Hanley

1 Answers

0
votes

Well the documentation is pretty straightforward on this:

Once you've SSH'ed into the Compute Engine instance, you can use the gsutil CLI to upload or download certain files into / from Cloud Storage with gsutil cp. For example, the following CLI command would copy a local file to the desired Cloud Storage bucket:

gsutil cp /path/to/my-file.mp4 gs://my-bucket 

Although, in your use-case it would make more sense to do it programmatically by using the Cloud Storage Client Libraries which are available in multiple programming languages. Let's say you want to use PHP for it:

  • You would first have to install the Client Library with:

    composer require google/cloud-storage

  • Set up authentication by first creating a Cloud IAM Service Account as mentioned here, giving it a role to access the Cloud Storage bucket(s) (in this case the role roles/storage.objectCreator would suffice if you simply want to upload objects), downloading the JSON key file into the Compute Engine instance, and setting the environment variable GOOGLE_APPLICATION_CREDENTIALS with:

    export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"

  • And then finally, you can upload a file with this sample code in PHP. There are multiple examples offered by Google Cloud when interacting with Cloud Storage that you can find here.

Alternatively, you can mount a Cloud Storage bucket as a filesystem on the Compute Engine instance, as described in the following page.