2013-03-06 2 views
1

J'essaie d'utiliser FileService pour créer un fichier sur Blobstore.FileServiceFactory getBlobKey throws IllegalArgumentException

regard Code comme suit:

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 
} 

Mais je reçois l'exception suivante:

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) 

Répondre

1

Correction du problème.

je dû assurer:

  1. j'appelle les openWriteChannel
  2. Ecrire un contenu (en option)
  3. Fermer le canal (close ou closeFinally)
  4. Et puis appelez getBlobKey

Cela garantit que getCachedKey méthode est appelée (je suppose) ou createHandle est disponible.

Avant, j'essayais de getBlobKey avant d'écrire du contenu.

Questions connexes