简体   繁体   English

使用Objectify Appengine存储大块

[英]Storing large blob with Objectify Appengine

I have this class which I want to persist using Objectify, this class will represent a data larger than 1MB so there's a List of Blob objects which represents a fragment of the byte array stored that is less than 1MB in size: 我有一个要使用Objectify持久化的类,该类将表示大于1MB的数据,因此存在一个Blob对象列表,该列表表示所存储的字节数组的片段,其大小小于1MB:

@Entity
public class BigBlob {

    @Id
    private Long id;
    public static final int FRAGMENT_LIMIT = 777 * 1024;
    @Serialized
    private List<Blob> fragments = new ArrayList<Blob>();

    ...

}

Yet, the the "fragments" is @Serialized, which will render the size of this BigBlob class/object larger than 1MB. 但是,“片段”是@Serialized,它将使此BigBlob类/对象的大小大于1MB。

Causing this error: 导致此错误:

com.google.apphosting.api.ApiProxy$RequestTooLargeException: The request to API call datastore_v3.Put() was too large.

If I use @Embedded annotation I get this error: 如果我使用@Embedded注解,则会出现此错误:

Cannot place array or collection properties inside @Embedded arrays or collections

How do I make sure that the "fragments" are stored as a separate entity? 如何确保“片段”存储为单独的实体?

BTW, I already have the byte chunking logic that chops the whole byte array and put the fragments into a List of Blob so this question does not pertain as to how to chop bytes. 顺便说一句,我已经有了字节分块逻辑,可以对整个字节数组进行切分并将片段放入Blob List ,因此该问题与如何切分字节无关。

Mostly what I want to know is more on the persisting side. 我想知道的主要是持久性方面。

You should store it in the Blobstore and just save the Blobkey in Objectify. 您应该将其存储在Blobstore中,然后将Blobkey保存在Objectify中。 Objectify works on top of the datastore, not the blobstore. Objectify在数据存储而不是Blob存储上运行。

Rick's answer is really the best - store blobs in the blobstore, especially if you are new to GAE and having conceptual issues with the datastore. Rick的答案确实是最好的-将Blob存储在Blob存储中,尤其是如果您不熟悉GAE并且数据存储存在概念性问题。

On the other hand, there are some good reasons to use split entities for storing blobs, especially if you are storing data that is close to the 1M edge. 另一方面,使用拆分实体来存储Blob有很多充分的理由,尤其是当您存储的数据接近1M边缘时。 You wouldn't want to do this with 100MB blobs, but 2MB blobs can make sense. 您不希望使用100MB的Blob来做到这一点,但是2MB的Blob可能很有意义。

First of all, you don't want serialized or embedded. 首先,您不需要序列化或嵌入式。 Those are simply ways to structure data inside a single entity. 这些只是在单个实体内构造数据的简单方法。

Also, there's no magic annotation that lets you split blobs across entities. 另外,没有魔术注释可让您在实体之间拆分Blob。 You have to do it all by hand. 您必须手动完成所有操作。 You don't need to actually create a 'master' or root entity; 您不需要实际创建“主”或根实体; just create all the entity fragments with a parent defined by an id (but no actual entity) and use an ancestor() query to fetch all the pieces. 只需使用由ID定义的父对象(而不是实际实体)创建所有实体片段,然后使用ancestor()查询来获取所有片段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM