如何调试 0 MB 未命名上传?

发布于 2024-12-16 00:00:22 字数 2430 浏览 3 评论 0原文

从数据存储控制台管理 blobstore 查看器中查看,许多文件的大小为 0:

在此处输入图像描述

您能否发表评论或说明原因这已经发生了吗?我认为我的文件上传代码非常干净,那么错误在哪里?

for upload in self.get_uploads():
    try:
        img = Image(reference=ad)
        img.primary_image = upload.key()
        img.put()
        ad.put()
    except:
        pass

我怀疑我可以通过 上传文件 到 blobstore 来重新创建此错误,然后将文件和零将创建上传。您认为我还应该如何解决这个错误?

谢谢

更新

我可以重现错误,只上传一个文件并将其他字段留空,然后空白字段将创建空白数据存储文件:

<tr><td>
<div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label>
  </div></td><td>
  <div class="adinput">
    <input type="file" name="file" size="35" id="file" />{% trans %}Optional{% endtrans %}{{resize}}
  </div>
  </td></tr><tr><td>
  <div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label>
  </div></td><td>
  <div class="adinput">
    <input type="file" name="file2" size="35" id="file2" /> {% trans %}Optional{% endtrans %}
  </div></td></tr><tr><td>
<div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label>
  </div></td><td>
  <div class="adinput">
    <input type="file" name="file3" size="35" id="file3" /> {% trans %}Optional{% endtrans %}
  </div>
  </td></tr><tr><td>
  <div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label>
  </div></td><td>
    <input type="file" name="file4" size="35" id="file4" /> {% trans %}Optional{% endtrans %}
  </td></tr><tr><td>
<div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label></div></td><td><div class="adinput"><input type="file" name="file5" size="35" id="file5" /> {% trans %}Optional{% endtrans %}</div></td></tr><tr><td></td><td><div class="labelform"></div><div class="adinput">

<input type="submit" name="validate" value='{% trans %}Go{% endtrans %}' /></div></td></tr>

Looking from the datastore console admin blobstore viewer it appears many files are 0 sizes:

enter image description here

Could you comment or say why this has happened? I think the file upload code I have is pretty clean so where is the bug?

for upload in self.get_uploads():
    try:
        img = Image(reference=ad)
        img.primary_image = upload.key()
        img.put()
        ad.put()
    except:
        pass

I suspect I can recreate this bug by uploading a file to the blobstore and then both the file and a zero upload will be created. How else do you think I should troubleshoot this bug?

Thank you

Update

I can reproduce the bug uploading just one file and leave the other fields blank then the blank fields will create the blank datastore files:

<tr><td>
<div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label>
  </div></td><td>
  <div class="adinput">
    <input type="file" name="file" size="35" id="file" />{% trans %}Optional{% endtrans %}{{resize}}
  </div>
  </td></tr><tr><td>
  <div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label>
  </div></td><td>
  <div class="adinput">
    <input type="file" name="file2" size="35" id="file2" /> {% trans %}Optional{% endtrans %}
  </div></td></tr><tr><td>
<div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label>
  </div></td><td>
  <div class="adinput">
    <input type="file" name="file3" size="35" id="file3" /> {% trans %}Optional{% endtrans %}
  </div>
  </td></tr><tr><td>
  <div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label>
  </div></td><td>
    <input type="file" name="file4" size="35" id="file4" /> {% trans %}Optional{% endtrans %}
  </td></tr><tr><td>
<div class="labelform">
    <label>{% trans %}Post a photo{% endtrans %}</label></div></td><td><div class="adinput"><input type="file" name="file5" size="35" id="file5" /> {% trans %}Optional{% endtrans %}</div></td></tr><tr><td></td><td><div class="labelform"></div><div class="adinput">

<input type="submit" name="validate" value='{% trans %}Go{% endtrans %}' /></div></td></tr>

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

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

发布评论

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

评论(2

不美如何 2024-12-23 00:00:22

您指定了多个文件字段,因此数据存储区正在尝试处理多个文件。这可能被视为 blobstore 中的错误(在这种情况下,您可以提交一个 ),但如果您的浏览器提交的是空字段,我不清楚正确的响应是什么。

您可以通过删除空文件来解决此问题,或者(更好)使用 Javascript 根据用户想要上传的实际文件数量自动添加和减去文件输入字段。

You're specifying multiple file fields, so the datastore is attempting to process multiple files. This might be considered a bug in the blobstore (in which case you could file one), but if your browser is submitting the empty fields, it's unclear to me what the proper response is.

You could work around this by deleting the empty files, or (better) by using Javascript to automatically add and subtract file input fields as required for the actual number of files the user wants to upload.

苦行僧 2024-12-23 00:00:22

使用谷歌的实验代码(需要针对多个文件进行调整)。

my_upload = self.request.POST['file']
my_data = my_upload.file.read()

if len(my_data) > 0:
    # Create the file
    file_name = files.blobstore.create(mime_type='application/octet')

    # Open the file and write to it
    with files.open(file_name, 'b') as f:
      f.write(my_data)

    # Finalize the file. Do this before attempting to read it.
    files.finalize(file_name)

    # Get the file's blob key
    blob_key = files.blobstore.get_blob_key(file_name)
    self.response.out.write(blob_key)

Using Google's experimental code (need to tweak it for multiple files).

my_upload = self.request.POST['file']
my_data = my_upload.file.read()

if len(my_data) > 0:
    # Create the file
    file_name = files.blobstore.create(mime_type='application/octet')

    # Open the file and write to it
    with files.open(file_name, 'b') as f:
      f.write(my_data)

    # Finalize the file. Do this before attempting to read it.
    files.finalize(file_name)

    # Get the file's blob key
    blob_key = files.blobstore.get_blob_key(file_name)
    self.response.out.write(blob_key)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文