将 blob 写入 blobstore

发布于 2024-12-12 12:32:00 字数 1394 浏览 0 评论 0原文

我尝试使用此处描述的方法写入 blobstore:

http ://code.google.com/appengine/docs/python/blobstore/overview.html#Writing_Files_to_the_Blobstore

我尝试使用remote_api来执行以下代码:

file_name = files.blobstore.create(mime_type='text/html',_blobinfo_uploaded_filename='sample.txt')
with files.open(file_name, 'a') as f:
    f.write('sample text for the sample blob')
files.finalize(file_name)

总是会引发错误(在上面的第三行):

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\file
s\file.py", line 310, in write
    self._make_rpc_call_with_retry('Append', request, response)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\file
s\file.py", line 388, in _make_rpc_call_with_retry
    _make_call(method, request, response)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\file
s\file.py", line 236, in _make_call
    _raise_app_error(e)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\file
s\file.py", line 179, in _raise_app_error
    raise FileNotOpenedError()
FileNotOpenedError

我尝试写入的文件非常小(< 20KB),因此它不是配额问题。我还缺少其他步骤吗?

I am trying to write to the blobstore using the method described here:

http://code.google.com/appengine/docs/python/blobstore/overview.html#Writing_Files_to_the_Blobstore

I tried using the remote_api to execute the following code:

file_name = files.blobstore.create(mime_type='text/html',_blobinfo_uploaded_filename='sample.txt')
with files.open(file_name, 'a') as f:
    f.write('sample text for the sample blob')
files.finalize(file_name)

invariably raises the error (at the third line above):

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\file
s\file.py", line 310, in write
    self._make_rpc_call_with_retry('Append', request, response)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\file
s\file.py", line 388, in _make_rpc_call_with_retry
    _make_call(method, request, response)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\file
s\file.py", line 236, in _make_call
    _raise_app_error(e)
  File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\file
s\file.py", line 179, in _raise_app_error
    raise FileNotOpenedError()
FileNotOpenedError

The file i am trying to write is very small (< 20KB) so its not a quota issue. Are there additional steps i am missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二货你真萌 2024-12-19 12:32:00

也许您可能需要添加以下模块,但如果您之前没有添加。

    from __future__ import with_statement 
 -->from google.appengine.api import files
    from google.appengine.ext import blobstore
    from google.appengine.ext.webapp import blobstore_handlers


    file_name = files.blobstore.create(mime_type='text/plain',_blobinfo_uploaded_filename='sample.txt')
    with files.open(file_name, 'a') as f:
         f.write('sample text for the sample blob') 
    files.finalize(file_name)

maybe you can need to add below module but if you dont previously add.

    from __future__ import with_statement 
 -->from google.appengine.api import files
    from google.appengine.ext import blobstore
    from google.appengine.ext.webapp import blobstore_handlers


    file_name = files.blobstore.create(mime_type='text/plain',_blobinfo_uploaded_filename='sample.txt')
    with files.open(file_name, 'a') as f:
         f.write('sample text for the sample blob') 
    files.finalize(file_name)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文