I am trying to upload blob to google blob store I am using this method to get upload Key
BlobKey key = blobstoreService.createGsBlobKey("/gs/saad");
I wonder how to create upload URL from this key ?
I know that i can get URL directly using the line bellow
String blobUploadUrl = blobstoreService.createUploadUrl("/saad");
but in this case I can't get the blob key which I need to store in my database in order to be able to download the file later.
You're going about this the wrong way. You don't create a BlobKey
first, you retrieve the key after uploading.
So you will:
1- Create an upload URL:
String blobUploadUrl = blobstoreService.createUploadUrl("/saad");
2- Upload to the URL (POST from your app/form).
3- After the upload, /saad
will be called automatically. You should have a POST handler mapped to /saad
. From there, you retrieve the blobs uploaded from the HttpServletRequest
object using blobstoreService.getBlobInfos(request)
or blobstoreService.getUploads(request)
.
See Uploading a blob for more info.