Fancybox 图片库 +斑点存储区
为了从 blobstore 检索图像,我通常执行以下操作并且它有效:
<img src="/image?blob_key={{ blob_key }}"></img>
据我了解 fancybox 并亲自尝试过:
$("a[rel=photo_collections]").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none',
});
<a rel="photo_collections" href="/image/photo.png"> Photos </a>
<a rel="photo_collections" href="/image/photo2.png"> Photos </a>
如果文件夹中有图像,则上面的图像库有效。
所以,我的问题是,如果我想从 Blobstore 而不是文件夹中检索图像怎么办?
所以,我尝试遵循它不起作用:
$("a[rel=photo_collections]").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none',
});
<a rel="photo_collections" href="/image/photo.png"> Photos </a>
<a rel="photo_collections" href="/image/photo2.png"> Photos </a>
// This part, the fancybox works but it doesn't display the image correctly. All it shows were some sort of binary data instead of image
<a rel="photo_collections" href="/image?blob_key={{ blob_key }}"
因此,我这里有两个主要问题:
- 如何解决上述问题?
- 如果我想做一些像 Google Plus/Facebook 照片查看器这样的事情,在查看图像时,用户可以发表评论。由于我需要更多 HTML 表单控制,这是否需要 HTML 内容库而不仅仅是图像库?
编辑
以下是处理从 Blobstore 检索到的图像的处理程序:
class RemoteDisplayImageHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
blob_key = self.request.GET.get('blob_key', None)
blob_info = blobstore.BlobInfo.get(blob_key)
logging.debug('blob_key=%s', blob_key)
logging.debug('blob_info=%s', blob_info)
if not blob_info:
raise Exception('Blob Key does not exist')
self.send_blob(blob_info)
For retrieving image from blobstore, I usually do the following and it works:
<img src="/image?blob_key={{ blob_key }}"></img>
As far as I read about fancybox and personally tried it:
$("a[rel=photo_collections]").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none',
});
<a rel="photo_collections" href="/image/photo.png"> Photos </a>
<a rel="photo_collections" href="/image/photo2.png"> Photos </a>
The above image gallery works if I have images in the folder.
So, my question is what if I want to retrieve images from Blobstore instead of folder?
So, I tried following it doesn't work:
$("a[rel=photo_collections]").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none',
});
<a rel="photo_collections" href="/image/photo.png"> Photos </a>
<a rel="photo_collections" href="/image/photo2.png"> Photos </a>
// This part, the fancybox works but it doesn't display the image correctly. All it shows were some sort of binary data instead of image
<a rel="photo_collections" href="/image?blob_key={{ blob_key }}"
Hence, I've two main questions here:
- How to solve the problem mentioned above ?
- If I wish to do something like Google Plus/Facebook Photo Viewer, where while viewing the images, user is able to make comments. Does this require HTML content gallery instead of just images gallery since I need more HTML form control?
EDIT
Following is the handler to serve the image retrieved from Blobstore:
class RemoteDisplayImageHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
blob_key = self.request.GET.get('blob_key', None)
blob_info = blobstore.BlobInfo.get(blob_key)
logging.debug('blob_key=%s', blob_key)
logging.debug('blob_info=%s', blob_info)
if not blob_info:
raise Exception('Blob Key does not exist')
self.send_blob(blob_info)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您的图像处理程序返回了错误的内容类型。确保在响应中正确设置
Content-Type
标头。It sounds like your image handler is returning the wrong content type. Make sure you set the
Content-Type
header correctly in the response.通过使用替代方案解决:
Solved by using alternative: