【问题标题】:javax.jdo.JDOException: string property file is too long. It cannot exceed 1000000 charactersjavax.jdo.JDOException:字符串属性文件太长。不能超过 1000000 个字符
【发布时间】:2012-03-19 13:54:20
【问题描述】:

我尝试将一个小型 TXT 文件 (4KB) 上传到 Google App Engine DataStore。当我在本地测试应用程序时,我没有问题并且文件成功保存;但是当我在 GAE 中尝试时,出现以下错误:

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;

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

【问题讨论】:

  • 每个数据存储实体的最大大小为1MB。看到你的文本文件只有 4KB,你能以某种方式将它多次添加到 DS 中吗?它可以解释为什么你会达到极限。
  • 我不这么认为,更新只执行一次。如果实体的大小大于 1MB,本地数据存储会抱怨吗?

标签: google-app-engine google-cloud-datastore jdo


【解决方案1】:

考虑将您的小文件放入 blobstore,然后将 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();
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 2011-05-03
    • 2018-12-21
    • 2012-08-06
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多