Fancybox 图片库 +斑点存储区

发布于 2024-12-03 16:02:00 字数 1715 浏览 1 评论 0原文

为了从 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 }}"            

因此,我这里有两个主要问题:

  1. 如何解决上述问题?
  2. 如果我想做一些像 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:

  1. How to solve the problem mentioned above ?
  2. 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 技术交流群。

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

发布评论

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

评论(2

偏闹i 2024-12-10 16:02:00

听起来您的图像处理程序返回了错误的内容类型。确保在响应中正确设置 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.

长伴 2024-12-10 16:02:00

通过使用替代方案解决:

            options.push({
                    'href'  : 'image_url',
                    'class' : 'iframe'
                });

            $.fancybox(options, {
                'padding'           : 0,
                'transitionIn'      : 'none',
                'transitionOut'     : 'none',
                'type'              : 'image',
                'changeFade'        : 0
            });

Solved by using alternative:

            options.push({
                    'href'  : 'image_url',
                    'class' : 'iframe'
                });

            $.fancybox(options, {
                'padding'           : 0,
                'transitionIn'      : 'none',
                'transitionOut'     : 'none',
                'type'              : 'image',
                'changeFade'        : 0
            });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文