public interface BlobstoreService
BlobstoreService
allows you to manage the creation and
serving of large, immutable blobs to users.Modifier and Type | Field and Description |
---|---|
static int |
MAX_BLOB_FETCH_SIZE |
Modifier and Type | Method and Description |
---|---|
BlobKey |
createGsBlobKey(java.lang.String filename)
Create a
BlobKey for a Google Storage File. |
java.lang.String |
createUploadUrl(java.lang.String successPath)
Create an absolute URL that can be used by a user to
asynchronously upload a large blob.
|
java.lang.String |
createUploadUrl(java.lang.String successPath,
UploadOptions uploadOptions)
Create an absolute URL that can be used by a user to
asynchronously upload a large blob.
|
void |
delete(BlobKey... blobKeys)
Permanently deletes the specified blobs.
|
byte[] |
fetchData(BlobKey blobKey,
long startIndex,
long endIndex)
Get fragment from specified blob.
|
java.util.Map<java.lang.String,java.util.List<BlobInfo>> |
getBlobInfos(HttpServletRequest request)
Returns the
BlobInfo for any files that were uploaded, keyed by the
upload form "name" field. |
ByteRange |
getByteRange(HttpServletRequest request)
Get byte range from the request.
|
java.util.Map<java.lang.String,java.util.List<FileInfo>> |
getFileInfos(HttpServletRequest request)
Returns the
FileInfo for any files that were uploaded, keyed by the
upload form "name" field. |
java.util.Map<java.lang.String,BlobKey> |
getUploadedBlobs(HttpServletRequest request)
Deprecated.
Use
getUploads(HttpServletRequest) instead. Note that getUploadedBlobs
does not handle cases where blobs have been uploaded using the
multiple="true" attribute of the file input form element. |
java.util.Map<java.lang.String,java.util.List<BlobKey>> |
getUploads(HttpServletRequest request)
Returns the
BlobKey for any files that were uploaded, keyed by the
upload form "name" field. |
void |
serve(BlobKey blobKey,
ByteRange byteRange,
HttpServletResponse response)
Arrange for the specified blob to be served as the response
content for the current request.
|
void |
serve(BlobKey blobKey,
HttpServletResponse response)
Arrange for the specified blob to be served as the response
content for the current request.
|
void |
serve(BlobKey blobKey,
java.lang.String rangeHeader,
HttpServletResponse response)
Arrange for the specified blob to be served as the response
content for the current request.
|
static final int MAX_BLOB_FETCH_SIZE
java.lang.String createUploadUrl(java.lang.String successPath)
successPath
- A relative URL which will be invoked
after the user successfully uploads a blob. Must start with a "/",
and must be URL-encoded.java.lang.IllegalArgumentException
- If successPath was not valid.BlobstoreFailureException
- If an error occurred while
communicating with the blobstore.java.lang.String createUploadUrl(java.lang.String successPath, UploadOptions uploadOptions)
successPath
- A relative URL which will be invoked
after the user successfully uploads a blob. Must start with a "/".uploadOptions
- Specific options applicable only for this
upload URL.java.lang.IllegalArgumentException
- If successPath was not valid.BlobstoreFailureException
- If an error occurred while
communicating with the blobstore.void serve(BlobKey blobKey, HttpServletResponse response) throws java.io.IOException
response
should be
uncommitted before invoking this method, and should be assumed to
be committed after invoking it. Any content written before
calling this method will be ignored. You may, however, append
custom headers before or after calling this method.
Range header will be automatically translated from the Content-Range header in the response.
blobKey
- Blob-key to serve in response.response
- HTTP response object.java.io.IOException
- If an I/O error occurred.java.lang.IllegalStateException
- If response
was already committed.void serve(BlobKey blobKey, ByteRange byteRange, HttpServletResponse response) throws java.io.IOException
response
should be
uncommitted before invoking this method, and should be assumed to
be committed after invoking it. Any content written before
calling this method will be ignored. You may, however, append
custom headers before or after calling this method.
This method will set the App Engine blob range header to serve a byte range of that blob.
blobKey
- Blob-key to serve in response.byteRange
- Byte range to serve in response.response
- HTTP response object.java.io.IOException
- If an I/O error occurred.java.lang.IllegalStateException
- If response
was already committed.void serve(BlobKey blobKey, java.lang.String rangeHeader, HttpServletResponse response) throws java.io.IOException
response
should be
uncommitted before invoking this method, and should be assumed to
be committed after invoking it. Any content written before
calling this method will be ignored. You may, however, append
custom headers before or after calling this method.
This method will set the App Engine blob range header to the content specified.
blobKey
- Blob-key to serve in response.rangeHeader
- Content for range header to serve.response
- HTTP response object.java.io.IOException
- If an I/O error occurred.java.lang.IllegalStateException
- If response
was already committed.ByteRange getByteRange(HttpServletRequest request)
request
- HTTP request object.RangeFormatException
- Unable to parse header because of invalid format.UnsupportedRangeFormatException
- Header is a valid HTTP range header, the specific
form is not supported by app engine. This includes unit types other than "bytes" and multiple
ranges.void delete(BlobKey... blobKeys)
BlobstoreFailureException
- If an error occurred while
communicating with the blobstore.@Deprecated java.util.Map<java.lang.String,BlobKey> getUploadedBlobs(HttpServletRequest request)
getUploads(HttpServletRequest)
instead. Note that getUploadedBlobs
does not handle cases where blobs have been uploaded using the
multiple="true" attribute of the file input form element.BlobKey
for any files that were uploaded, keyed by the
upload form "name" field.
This method should only be called from within a request served by
the destination of a createUploadUrl
call.
java.lang.IllegalStateException
- If not called from a blob upload
callback request.java.util.Map<java.lang.String,java.util.List<BlobKey>> getUploads(HttpServletRequest request)
BlobKey
for any files that were uploaded, keyed by the
upload form "name" field.
This method should only be called from within a request served by
the destination of a createUploadUrl
call.java.lang.IllegalStateException
- If not called from a blob upload
callback request.getBlobInfos(HttpServletRequest)
,
getFileInfos(HttpServletRequest)
java.util.Map<java.lang.String,java.util.List<BlobInfo>> getBlobInfos(HttpServletRequest request)
BlobInfo
for any files that were uploaded, keyed by the
upload form "name" field.
This method should only be called from within a request served by
the destination of a createUploadUrl
call.java.lang.IllegalStateException
- If not called from a blob upload
callback request.getFileInfos(HttpServletRequest)
,
getUploads(HttpServletRequest)
java.util.Map<java.lang.String,java.util.List<FileInfo>> getFileInfos(HttpServletRequest request)
FileInfo
for any files that were uploaded, keyed by the
upload form "name" field.
This method should only be called from within a request served by
the destination of a createUploadUrl
call.
Prefer this method over getBlobInfos
or getUploads
if
uploading files to Cloud Storage, as the FileInfo contains the name of the
created filename in Cloud Storage.java.lang.IllegalStateException
- If not called from a blob upload
callback request.getBlobInfos(HttpServletRequest)
,
getUploads(HttpServletRequest)
byte[] fetchData(BlobKey blobKey, long startIndex, long endIndex)
blobKey
- Blob-key from which to fetch data.startIndex
- Start index of data to fetch.endIndex
- End index (inclusive) of data to fetch.java.lang.IllegalArgumentException
- If blob not found, indexes are negative,
indexes are inverted or fetch size is too large.java.lang.SecurityException
- If the application does not have acces to the blob.BlobstoreFailureException
- If an error occurred while communicating
with the blobstore.BlobKey createGsBlobKey(java.lang.String filename)
BlobKey
for a Google Storage File.
The existance of the file represented by filename is not checked, hence
a BlobKey can be created for a file that does not currently exist.
You can safely persist the BlobKey
generated by this function.
The created BlobKey
can then be used as a parameter in API methods
that can support objects in Google Storage, for example serve
.
filename
- The Google Storage filename. The filename must be in the
format "/gs/bucket_name/object_name".java.lang.IllegalArgumentException
- If the filename does not have the prefix
"/gs/".