gvaish
gvaish

Reputation: 9404

FileServiceFactory getBlobKey throws IllegalArgumentException

I am trying to use FileService to create a file on Blobstore.

Code look as follows:

public static BlobKey save(String mimeType, String value, String filename) throws IOException
{
    FileService svc = FileServiceFactory.getFileService();
    AppEngineFile file = filename == null ? svc.createNewBlobFile(mimeType) : svc.createNewBlobFile(mimeType, filename);
    key = svc.getBlobKey(file); //throws exception
}

But I get the following exception:

java.lang.IllegalArgumentException: creation_handle: String properties must be 500 characters or less.  
Instead, use com.google.appengine.api.datastore.Text, which can store strings of any length.
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:242)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:207)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:173)
    at com.google.appengine.api.datastore.Query$FilterPredicate.<init>(Query.java:900)
    at com.google.appengine.api.datastore.Query$FilterOperator.of(Query.java:75)
    at com.google.appengine.api.datastore.Query.addFilter(Query.java:351)
    at com.google.appengine.api.files.FileServiceImpl.getBlobKey(FileServiceImpl.java:329)

Upvotes: 1

Views: 193

Answers (1)

gvaish
gvaish

Reputation: 9404

Fixed the problem.

I had to ensure the following:

  1. I call the openWriteChannel
  2. Write some content (optional)
  3. Close the channel (close or closeFinally)
  4. And then call getBlobKey

This ensures that getCachedKey method is called (I guess so) or createHandle is available.

I was, earlier, trying to getBlobKey before writing content.

Upvotes: 1

Related Questions