gpt4 book ai didi

google-app-engine - AppEngine IO 复制问题导致 "API error 10 (file: FILE_NOT_OPENED)"

转载 作者:IT王子 更新时间:2023-10-29 01:10:48 26 4
gpt4 key购买 nike

我的 GoLang AppEngine 代码正在解压缩一个 ZIP 文件,然后将每个文件保存为 BlobStore 内容。我已经看到保存数据需要 30 多秒,然后失败并显示“API 错误 10(文件:FILE_NOT_OPENED)”。正在写入的未压缩文件的大小约为 1.5 兆字节。下面是从 Zip 阅读器复制到新 BlogStore 项目的代码:

func storeBlob(c appengine.Context, rc io.Reader, mimeType string) (appengine.BlobKey, error) {

c.Infof("Creating new blob of type: [%v]", mimeType)
var key appengine.BlobKey
w, err := blobstore.Create(c, mimeType)
if err != nil {
return "", err
}

c.Infof("Copying blob data")
_, err = io.Copy(w, rc)
if err != nil {
return "", err
}

c.Infof("Closing Blob")
err = w.Close()
if err != nil {
return "", err
}

c.Infof("Getting Blob Key")
key, err = w.Key()
if err != nil {
return "", err
}
return key, nil

生产应用引擎服务器锁定 30 秒,然后在 io.Copy 调用上报告错误。关于如何解决此问题的任何想法?

最佳答案

此错误是因为您的请求超时。 Create 发出类似于 this 的 Protocol Buffer 请求:

oreq := &filepb.OpenRequest{
Filename: res.Filename,
ContentType: filepb.FileContentType_RAW.Enum(),
OpenMode: filepb.OpenRequest_APPEND.Enum(),
ExclusiveLock: proto.Bool(true),
}

对应definition :

type OpenRequest struct {
Filename *string `protobuf:"bytes,1,req,name=filename" json:"filename,omitempty"`
ContentType *FileContentType_ContentType `protobuf:"varint,2,req,name=content_type,enum=files.FileContentType_ContentType" json:"content_type,omitempty"`
OpenMode *OpenRequest_OpenMode `protobuf:"varint,3,req,name=open_mode,enum=files.OpenRequest_OpenMode" json:"open_mode,omitempty"`
ExclusiveLock *bool `protobuf:"varint,4,opt,name=exclusive_lock,def=0" json:"exclusive_lock,omitempty"`
BufferedOutput *bool `protobuf:"varint,5,opt,name=buffered_output,def=0" json:"buffered_output,omitempty"`
OpenLeaseTimeSeconds *int32 `protobuf:"varint,6,opt,name=open_lease_time_seconds,def=30" json:"open_lease_time_seconds,omitempty"`
XXX_unrecognized []byte `json:"-"`
}

注意 OpenLeaseTimeSeconds 未设置。默认为 30 秒:

const Default_OpenRequest_OpenLeaseTimeSeconds int32 = 30

所以它可能正在关闭您下面的连接。

你有两个选择:

  1. 编写您自己的 Create 方法,将租约时间设置为大于 30 秒。从那以后你最多可以做的是 60 秒你的请求will be killed , 在这种情况下你需要使用 Task Queue .

  2. API 已弃用:

    Warning: The Files API feature used here to write files to Blobstore has been deprecated and is going to be removed at some time in the future, in favor of writing files to Google Cloud Storage and using Blobstore to serve them. For more information, please visit Google Cloud Storage.

    所以也许您应该改用谷歌存储。

关于google-app-engine - AppEngine IO 复制问题导致 "API error 10 (file: FILE_NOT_OPENED)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29850760/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com