2012-03-01 89 views
2

我尝试上传一个小的TXT文件(4KB)到Google App Engine DataStore。当我在本地测试应用程序时,我没有任何问题,并且文件成功保存;但是当我在GAE试试我得到以下错误:javax.jdo.JDOException:字符串属性文件太长。它不能超过1000000个字符

javax.jdo.JDOException: string property file is too long. It cannot exceed 1000000 characters. 
NestedThrowables: 
java.lang.IllegalArgumentException: string property file is too long. It cannot exceed 1000000 characters 

在GAE控制台,日志下面说:

com.google.apphosting.api.ApiProxy$RequestTooLargeException: The request to API call datastore_v3.Put() was too large. 
at com.google.apphosting.runtime.ApiProxyImpl$AsyncApiFuture.success(ApiProxyImpl.java:480) 
at com.google.apphosting.runtime.ApiProxyImpl$AsyncApiFuture.success(ApiProxyImpl.java:380) 
at com.google.net.rpc3.client.RpcStub$RpcCallbackDispatcher$1.runInContext(RpcStub.java:746) 
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:455) 
at com.google.tracing.TraceContext.runInContext(TraceContext.java:695) 
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333) 

包含该文件的实体的JDO映射如下:

@PersistenceCapable(identityType = IdentityType.APPLICATION) 
public class AppointmentEntity implements Serializable { 
    @PrimaryKey 
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 
    private Long id;  
    @Persistent(serialized = "true") 
    private DownloadableFile file; 

而且DownloadableFile是:

public class DownloadableFile implements Serializable { 
    private byte[] content; 
    private String filename; 
    private String mimeType; 

任何想法是什么错?我读了一些关于会话大小和实体大小的内容,但小文件大小让我放弃了这些理论。

+0

每个数据存储实体的最大尺寸为[1MB](http://code.google.com/appengine/文档/蟒蛇/数据存储/ overview.html#Datastore_Statistics)。看到你的文本文件只有4KB,你能以某种方式将它添加到DS多次?这也许可以解释为什么你达到了极限。 – 2012-03-01 14:35:49

+0

我不这么认为,更新只执行一次。如果实体的大小大于1MB,那么本地数据存储会抱怨? – 2012-03-01 14:47:59

回答

0

考虑将在Blob存储你的小文件,然后存储的BlobKey在数据存储:

@PersistenceCapable() 
public class FileEntity { 

    @PrimaryKey 
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 
    protected Key key; 


    @Persistent 
    private BlobKey blobKey; 

} 




private void createBlobStoreEntity() throws IOException{ 
     final PersistenceManager pm = PMF.get().getPersistenceManager(); 
     final FileService fileService = FileServiceFactory.getFileService(); 
     final AppEngineFile file = fileService.createNewBlobFile(Const.CONTENT_TYPE_PLAIN); 
     final String path = file.getFullPath(); 
     final FileWriteChannel writeChannel = fileService.openWriteChannel(file, true); 
     PrintWriter out = new PrintWriter(Channels.newWriter(writeChannel, "UTF8")); 
     try { 

      out.println(txt); 
      out.close(); 
      writeChannel.closeFinally(); 
      final BlobKey key = fileService.getBlobKey(file); 

      final ValueBlobStore store = new 
        FileEntity(key); 

      pm.makePersistent(store); 
      pm.flush(); 

     } 
     finally { 
      out.close(); 
      pm.close(); 
     } 
    } 
相关问题