如何将图像从url上传到Blobstore?(How to upload image from url to Blobstore?)
如果blobstore blob,Google App Engine文件API现在支持编程创建。
我试图通过http获取图像并将其存储到blobstore来尝试这个:
file_name = files.blobstore.create(mime_type='image/jpeg') image = urllib2.urlopen(url) with files.open(file_name, 'a') as f: f.write(image) # LINE 142 files.finalize(file_name) blob_key = files.blobstore.get_blob_key(file_name)
此代码抛出错误:
File "/Users/willmerydith/repos/spam/admin.py", line 142, in post f.write(image) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/files/file.py", line 364, in write self._make_rpc_call_with_retry('Append', request, response) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/files/file.py", line 472, in _make_rpc_call_with_retry _make_call(method, request, response) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/files/file.py", line 229, in _make_call rpc.check_success() File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 558, in check_success self.__rpc.CheckSuccess() File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitImpl self.request, self.response) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub.py", line 80, in MakeSyncCall if request.ByteSize() > self.__max_request_size: File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/files/file_service_pb.py", line 1923, in ByteSize n += self.lengthString(len(self.data_)) AttributeError: addinfourl instance has no attribute '__len__'
我怀疑它正在破裂,因为我超出了尺寸限制。 这是由于我将图像写入blobstore的方式吗? Blobstores的大小限制为2 GB,我测试的图像小于200-300 KB。
The Google App Engine Files API now supports programmatic creation if blobstore blobs.
I'm trying this out by attempting to fetch an image over http and store it to the blobstore:
file_name = files.blobstore.create(mime_type='image/jpeg') image = urllib2.urlopen(url) with files.open(file_name, 'a') as f: f.write(image) # LINE 142 files.finalize(file_name) blob_key = files.blobstore.get_blob_key(file_name)
This code is throwing the error:
File "/Users/willmerydith/repos/spam/admin.py", line 142, in post f.write(image) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/files/file.py", line 364, in write self._make_rpc_call_with_retry('Append', request, response) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/files/file.py", line 472, in _make_rpc_call_with_retry _make_call(method, request, response) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/files/file.py", line 229, in _make_call rpc.check_success() File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 558, in check_success self.__rpc.CheckSuccess() File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitImpl self.request, self.response) File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub.py", line 80, in MakeSyncCall if request.ByteSize() > self.__max_request_size: File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/files/file_service_pb.py", line 1923, in ByteSize n += self.lengthString(len(self.data_)) AttributeError: addinfourl instance has no attribute '__len__'
I suspect it is breaking because I am exceeding a size limit. Is that due to the way I am writing the image to the blobstore? The size limit for Blobstores is 2 GB, and the images I am testing are less than 200-300 KB.
原文:https://stackoverflow.com/questions/5665966
最满意答案
你需要改变两件事:
- 应用
line-height: 30px;
到<li>
元素。 这是因为您的图像高度为30像素。- 应用
vertical-align: bottom;
到你的<span>
与图像。 这是将图像与文本垂直对齐。此外,这将破坏行之间的填充,因此您可能还想为
<li>
元素添加一些底部填充/边距。结果代码:
第1步 :
.footer .footer-contact-list li { position: relative; line-height: 30px; /* add this */ /* here you may also add some bottom margin/padding */ }
第2步 :
.footer .footer-contact-list li span { height: 30px; width: 30px; border-radius: 50%; background: #a32020; display: inline-block; margin: 0 5px 0 0; position: relative; vertical-align: bottom; /* add this */ }
You need to change two things:
- Apply
line-height: 30px;
to the<li>
element. This is because your image is 30px in height.- Apply
vertical-align: bottom;
to your<span>
with the image. This is to vertically align your image with the text.Also, this will break your padding between the lines, so you may want to add some bottom padding/margin to
<li>
elements as well.The resulting code:
Step 1:
.footer .footer-contact-list li { position: relative; line-height: 30px; /* add this */ /* here you may also add some bottom margin/padding */ }
Step 2:
.footer .footer-contact-list li span { height: 30px; width: 30px; border-radius: 50%; background: #a32020; display: inline-block; margin: 0 5px 0 0; position: relative; vertical-align: bottom; /* add this */ }
相关问答
更多-
在RTE文本中用
- 标签包装
- 标签(Wrap
- tags with
- tag in RTE text)
如果你只是把它作为一个字符串返回,这是一个正则表达式解决方案,应该起作用,或者至少作为一个好的起点。 String pattern1 = "(?\\s{0,100})(- )"; String replace1 = "
- "; String pattern2 = " (?!\\s{0,100}
- )"; String replace2 = "
- 标签,前面没有
标签(忽略它们之间的任何空格),然后用开头如果li很长,我如何得到一个无序列表来阻止文字换行?(How do I get an unordered list to stop word wrapping if an li is long?)[2023-11-16]
尝试使用nowrap : li { white-space: nowrap; } Try using nowrap: li { white-space: nowrap; }Css如何在li中包装文本(Css how to wrap text in li)[2022-09-02]
你可以使用word-wrap: break-word; 在li 。 检查下面的更新片段.. .dropdown-menu li, .dropdown-menu li a { white-space: normal; float: left; width: 100%; height: auto; word-wrap: break-word; }