dongtan9518 2013-11-22 11:40
浏览 108

是否可以在GAE Golang Blobstore中存储任意数据?

I am creating a large database application in Google App Engine Go. Most of my pieces of data are small, so I have no problem storing them in Datastore. However, I know I will run into a few entries that will be a few megabytes big, so I will have to use Blobstore to save them.

Looking at the reference for Blobstore, it appears that the service was mainly intended to be used for files being uploaded to the service. What are the functions I need to call to store arbitrary data in the Blobstore like I would in Datastore? I can already convert the data to []byte and I don't need to index anything in the blob, just to store and fetch it by ID.

  • 写回答

2条回答 默认 最新

  • doumei1955 2013-11-22 14:51
    关注

    There are two ways that you could write files to the blobstore

    One is to use a deprecated API documented at the end of the page for the blobstore. Their example code is below.

    The approach that they are going to be switching to is storing files in Google cloud storage and serving them via the blobstore.

    The other approach would be to simulate a user upload in some fashion. Go has an http client that can send files to be uploaded to web addresses. That would be a hacky way to do it though.

    var k appengine.BlobKey
    w, err := blobstore.Create(c, "application/octet-stream")
    if err != nil {
            return k, err
    }
    _, err = w.Write([]byte("... some data ..."))
    if err != nil {
            return k, err
    }
    err = w.Close()
    if err != nil {
            return k, err
    }
    return w.Key()
    
    评论

报告相同问题?