You have to use Blobstore for uploading.
Call blobstoreService.createUploadUrl
to create an upload URL for the form that the user will fill out, passing the application path to load when the POST of the form is completed.
<body>
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<input type="submit" value="Submit">
</form>
</body>
and then in servlet:
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
List<BlobKey> blobKeys = blobs.get("myFile");
You can upload files to Storage directly, but passing UploadOptions
to .createUploadUrl
:
UploadOptions options = new UploadOptions.Builder().withGoogleStorageBucketName("mybucket");
String uploadUrl = blobstoreService.createUploadUrl("/upload", options)
Follow documentation https://cloud.google.com/appengine/docs/java/blobstore/#Java_Uploading_a_blob