如何调试 0 MB 未命名上传?
从数据存储控制台管理 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您指定了多个文件字段,因此数据存储区正在尝试处理多个文件。这可能被视为 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.
使用谷歌的实验代码(需要针对多个文件进行调整)。
Using Google's experimental code (need to tweak it for multiple files).