Skip to content
Advertisement

Spring Boot – Download a file from GCP Bucket

I’ve a Spring Boot Application and I have to develop an API to download a file from GCP bucket. So I have the download path and the name of the bucket, e.g.

my_bucket = "bucketTest"
download_path = bucketTest + "/file.txt"

Before I start writing the code for download, what are the preliminary steps? I read that I need a GOOGLE_APPLICATION_CREDENTIALS environment variable, where can I find it? Once I set this environment variable, do I just need to write the download code or are there some setup inside the controller function?

Advertisement

Answer

Maybe this topic can help : spring controller download file GCS

For GOOGLE_APPLICATION_CREDENTIALS it allows an application to be authenticated on GCP.

  • Firstly you have to create a service account on IAM GCP page with the needed privileges.
  • Download a json key for this service account.
  • Set the GOOGLE_APPLICATION_CREDENTIALS env var that targets on the path of the Service Account json key, before to start main and entrypoint of your Spring Boot application.
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement