0

I'm having multiple problems with appengine (java/jersey), but now I'm stucked with uploading files via multipart.

I've read this answer: https://stackoverflow.com/a/31325201

It worked for localhost, but when I upload to appengine, it shows the same error when starting the server:

java.lang.SecurityException: Unable to create temporary file

Does anyone know why it can be?

Thanks!

Community
  • 1
  • 1
Javier Manzano
  • 4,761
  • 16
  • 56
  • 86

1 Answers1

1

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

Igor Artamonov
  • 35,450
  • 10
  • 82
  • 113
  • 1
    it used to be better documentation before reorganization, "upload" was like a first level topic in navigation panel. but now only people who knows what "Blobstore" mean can find this :( – Igor Artamonov Jun 09 '16 at 16:55
  • Wow! thanks! couldn't find that... but... I uploading this images to Cloud Storage, can I upload the files after receiving them with blobstore? – Javier Manzano Jun 09 '16 at 17:05
  • 1
    you can upload to Cloud Storage directly, actually: https://cloud.google.com/appengine/docs/java/blobstore/#Java_Using_the_Blobstore_API_with_Google_Cloud_Storage – Igor Artamonov Jun 09 '16 at 17:05
  • I would recommend to *not* use Blobstore or `createUploadUrl` anymore. This method creates shadow entities in the Blobstore, that stay there forever. Besides, it's no longer necessary. – Andrei Volgin Jun 09 '16 at 19:29
  • @AndreiVolgin what is the current recommendation btw? i'm using Flexible VM mostly, witch supports standard uploads, so I probably missed what have changed in Standard VM for uploads – Igor Artamonov Jun 20 '16 at 11:21