是否可以在GAE Golang Blobstore中存储任意数据? [英] Is it possible to store arbitrary data in GAE Golang Blobstore?

查看:169
本文介绍了是否可以在GAE Golang Blobstore中存储任意数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google App Engine Go中创建了一个大型数据库应用程序。我的大部分数据都很小,因此我在将它们存储在数据存储中没有问题。但是,我知道我会遇到几个大小为几兆字节的条目,因此我必须使用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.

查找的引用页面上的https://developers.google.com/appengine/docs/go/blobstore/rel =nofollow>,似乎该服务主要用于文件上传到服务。我需要调用哪些函数来存储Blobstore中的任意数据,就像我在Datastore中一样?我可以将数据转换为[]字节,我不需要索引blob中的任何东西,只是存储和获取它的ID。

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.

推荐答案

有两种方法可以将文件写入blobstore

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

一种是使用页面末尾记录的弃用API blobstore。他们的示例代码如下。

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

他们将要切换到的方法是将文件存储在Google云存储中,并通过blobstore提供它们。

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

另一种方法是以某种方式模拟用户上传。 Go有一个http客户端,可以发送要上传到网址的文件。这将是一个黑客的方法,但它。

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()

这篇关于是否可以在GAE Golang Blobstore中存储任意数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆