2012-03-01 73 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(); 
     } 
    } 
相關問題