Skip to content

Commit c1bf2f8

Browse files
author
Ajay Kannan
committed
Update gcloud-java version to 0.1.5 and clean up cloudstorage sample
1 parent 26f687a commit c1bf2f8

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

datastore/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<dependency>
2424
<groupId>com.google.gcloud</groupId>
2525
<artifactId>gcloud-java-datastore</artifactId>
26-
<version>0.1.4</version>
26+
<version>0.1.5</version>
2727
</dependency>
2828
<dependency>
2929
<groupId>junit</groupId>

managed_vms/cloudstorage/README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
# Cloud Storage sample for Google Maanged VMs
2-
This sample demonstrates how to use [Cloud Storage](https://cloud.google.com/storage/) on Google Managed VMs
1+
# Cloud Storage sample for Google Managed VMs
2+
This sample demonstrates how to use [Cloud Storage](https://cloud.google.com/storage/) on Google Managed VMs.
3+
34
## Setup
45
Before you can run or deploy the sample, you will need to do the following:
6+
57
1. Enable the Cloud Storage API in the [Google Developers Console](https://console.developers.google.com/project/_/apiui/apiview/storage/overview).
6-
1. Create a Cloud Storage Bucket. You can do this with the [Google Cloud SDK](https://cloud.google.com/sdk) with the following command:
7-
$ gsutil mb gs://[your-bucket-name]
8-
1. Set the default ACL on your bucket to public read in order to serve files directly from Cloud Storage. You can do this with the [Google Cloud SDK](https://cloud.google.com/sdk) with the following command:
9-
$ gsutil defacl set public-read gs://[your-bucket-name]
10-
1. Update the bucket name in ``src/main/appengine/app.yaml``.
8+
2. Create a Cloud Storage Bucket. You can do this with the [Google Cloud SDK](https://cloud.google.com/sdk) using the following command:
9+
10+
```
11+
$ gsutil mb gs://[your-bucket-name]
12+
```
13+
3. Set the default ACL on your bucket to public read in order to serve files directly from Cloud Storage. You can do this with the [Google Cloud SDK](https://cloud.google.com/sdk) using the following command:
14+
15+
```
16+
$ gsutil defacl set public-read gs://[your-bucket-name]
17+
```
18+
4. Update the bucket name in `src/main/appengine/app.yaml`. This makes the bucket name an environment variable in deployment. You still need to set the environment variable when running locally, as shown below.
19+
1120
## Running locally
21+
$ export BUCKET_NAME=[your-bucket-name]
1222
$ mvn clean jetty:run
23+
1324
## Deploying
1425
$ mvn clean gcloud:deploy

managed_vms/cloudstorage/src/main/java/com/example/managedvms/cloudstorage/UploadServlet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.example.managedvms.cloudstorage;
1818

1919
import com.google.gcloud.storage.Acl;
20+
import com.google.gcloud.storage.Blob;
2021
import com.google.gcloud.storage.BlobInfo;
2122
import com.google.gcloud.storage.Storage;
2223
import com.google.gcloud.storage.StorageOptions;
@@ -57,14 +58,13 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOEx
5758
List<Acl> acls = new ArrayList<>();
5859
acls.add(Acl.of(Acl.User.ofAllUsers(), Acl.Role.READER));
5960
// the inputstream is closed by default, so we don't need to close it here
60-
BlobInfo blobInfo =
61+
Blob blob =
6162
storage.create(
6263
BlobInfo.builder(BUCKET_NAME, fileName).acl(acls).build(),
6364
filePart.getInputStream());
64-
blobInfo = storage.get(BUCKET_NAME, fileName);
6565

6666
// return the public download link
67-
resp.getWriter().print(blobInfo.mediaLink());
67+
resp.getWriter().print(blob.mediaLink());
6868
}
6969
}
7070
// [END example]

managed_vms/sparkjava/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<dependency>
3939
<groupId>com.google.gcloud</groupId>
4040
<artifactId>gcloud-java</artifactId>
41-
<version>0.1.4</version>
41+
<version>0.1.5</version>
4242
</dependency>
4343
</dependencies>
4444
<build>

0 commit comments

Comments
 (0)