treetory / spring-cloud-gcp-storage-resource-sample

GCP storage SDK 테스트

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Cloud GCP Storage Starter Example

This code sample demonstrates how to read and write files with the Spring Resource abstraction for Google Cloud Storage using the Spring Cloud GCP Storage Starter.

This content is also available in the Reading and Writing Files with Spring Resource Abstraction codelab.

Running the example

open btn

  1. Make sure that you have the Cloud SDK configured by following these instructions.

  2. Create a new bucket in Google Cloud Storage. You can use the gsutil command that comes with the Cloud SDK.

    $ BUCKET=spring-bucket-$USER
    $ gsutil makebucket gs://$BUCKET
  3. Transfer the local my-file.txt file to the bucket.

    $ gsutil copy my-file.txt gs://$BUCKET
  4. Run $ mvn clean install from the root directory of the project.

  5. In the same directory as this sample (spring-cloud-gcp-samples/spring-cloud-gcp-storage-resource-sample), edit the src/main/resources/application.properties and set the gcs-resource-test-bucket property to the name of your bucket that you created in Step 2.

  6. Start the GcsApplication Spring Boot app.

    $ mvn spring-boot:run
  7. Navigate to http://localhost:8080/ in your browser to print the contents of the file you uploaded in 3. You can also use the Web Preview button in Cloud Shell to preview the app on port 8080.

  8. To update the file contents, send a POST request to the same endpoint using curl:

    $ curl -d 'new message' -H 'Content-Type: text/plain' localhost:8080

    You should see a confirmation that the contents of the file were updated.

    However, let’s verify by going to http://localhost:8080/ or the Web Preview URL.

About

GCP storage SDK 테스트


Languages

Language:Java 100.0%