Interface BlobstoreService


  • public interface BlobstoreService
    BlobstoreService allows you to manage the creation and serving of large, immutable blobs to users.
    • Method Detail

      • createUploadUrl

        String createUploadUrl​(String successPath)
        Create an absolute URL that can be used by a user to asynchronously upload a large blob. Upon completion of the upload, a callback is made to the specified URL.
        Parameters:
        successPath - A relative URL which will be invoked after the user successfully uploads a blob. Must start with a "/", and must be URL-encoded.
        Throws:
        IllegalArgumentException - If successPath was not valid.
        BlobstoreFailureException - If an error occurred while communicating with the blobstore.
      • createUploadUrl

        String createUploadUrl​(String successPath,
                               UploadOptions uploadOptions)
        Create an absolute URL that can be used by a user to asynchronously upload a large blob. Upon completion of the upload, a callback is made to the specified URL.
        Parameters:
        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.
        Throws:
        IllegalArgumentException - If successPath was not valid.
        BlobstoreFailureException - If an error occurred while communicating with the blobstore.
      • serve

        void serve​(BlobKey blobKey,
                   javax.servlet.http.HttpServletResponse response)
            throws IOException
        Arrange for the specified blob to be served as the response content for the current request. 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.

        Parameters:
        blobKey - Blob-key to serve in response.
        response - HTTP response object.
        Throws:
        IOException - If an I/O error occurred.
        IllegalStateException - If response was already committed.
      • serve

        void serve​(BlobKey blobKey,
                   @Nullable ByteRange byteRange,
                   javax.servlet.http.HttpServletResponse response)
            throws IOException
        Arrange for the specified blob to be served as the response content for the current request. 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.

        Parameters:
        blobKey - Blob-key to serve in response.
        byteRange - Byte range to serve in response.
        response - HTTP response object.
        Throws:
        IOException - If an I/O error occurred.
        IllegalStateException - If response was already committed.
      • serve

        void serve​(BlobKey blobKey,
                   String rangeHeader,
                   javax.servlet.http.HttpServletResponse response)
            throws IOException
        Arrange for the specified blob to be served as the response content for the current request. 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.

        Parameters:
        blobKey - Blob-key to serve in response.
        rangeHeader - Content for range header to serve.
        response - HTTP response object.
        Throws:
        IOException - If an I/O error occurred.
        IllegalStateException - If response was already committed.
      • getByteRange

        @Nullable ByteRange getByteRange​(javax.servlet.http.HttpServletRequest request)
        Get byte range from the request.
        Parameters:
        request - HTTP request object.
        Returns:
        Byte range as parsed from the HTTP range header. null if there is no header.
        Throws:
        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.
      • delete

        void delete​(BlobKey... blobKeys)
        Permanently deletes the specified blobs. Deleting unknown blobs is a no-op.
        Throws:
        BlobstoreFailureException - If an error occurred while communicating with the blobstore.
      • getUploadedBlobs

        @Deprecated
        Map<String,​BlobKey> getUploadedBlobs​(javax.servlet.http.HttpServletRequest request)
        Deprecated.
        Use getUploads(javax.servlet.http.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.
        Returns the 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.

        Throws:
        IllegalStateException - If not called from a blob upload callback request.
      • fetchData

        byte[] fetchData​(BlobKey blobKey,
                         long startIndex,
                         long endIndex)
        Get fragment from specified blob.
        Parameters:
        blobKey - Blob-key from which to fetch data.
        startIndex - Start index of data to fetch.
        endIndex - End index (inclusive) of data to fetch.
        Throws:
        IllegalArgumentException - If blob not found, indexes are negative, indexes are inverted or fetch size is too large.
        SecurityException - If the application does not have access to the blob.
        BlobstoreFailureException - If an error occurred while communicating with the blobstore.