如何在浏览器中显示从云存储下载的图像?

时间:2017-06-23 13:58:23

标签: javascript node.js google-cloud-platform google-cloud-storage

目前,我从云存储桶下载图像,在base64中对其进行编码,然后将其传递到img标记的router.post('/images', function(req, res, next) { var image = bucket.file(req.body.image); image.download(function(err, contents) { if (err) { console.log(err); } else { var resultImage = base64_encode(contents); var index = req.body.index; var returnObject = { image: resultImage, index: index } res.send(returnObject); } }); }); 属性中的数据uri。

还有其他办法吗?

  File "manage.py", line 28, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/vol1/geonode/geonode/geonode/geoserver/management/commands/updatelayers.py", line 108, in handle
    remove_deleted=remove_deleted)
  File "/vol1/geonode/geonode/geonode/geoserver/helpers.py", line 458, in gs_slurp
    "bbox_y1": Decimal(resource.latlon_bbox[3])
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 154, in get_or_create
    return self.get_queryset().get_or_create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/modeltranslation/manager.py", line 341, in get_or_create
    return super(MultilingualQuerySet, self).get_or_create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 383, in get_or_create
    obj.save(force_insert=True, using=self.db)
  File "/usr/local/lib/python2.7/dist-packages/polymorphic/polymorphic_model.py", line 90, in save
    return super(PolymorphicModel, self).save(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 545, in save
    force_update=force_update, update_fields=update_fields)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 582, in save_base
    update_fields=update_fields, raw=raw, using=using)
  File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 185, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/vol1/geonode/geonode/geonode/geoserver/signals.py", line 470, in geoserver_post_save
    set_styles(instance, gs_catalog)
  File "/vol1/geonode/geonode/geonode/geoserver/helpers.py", line 776, in set_styles
    default_style = gs_layer.default_style
  File "/usr/local/lib/python2.7/dist-packages/geoserver/layer.py", line 103, in _get_default_style
    return self._resolve_style(element) if element is not None else None
  File "/usr/local/lib/python2.7/dist-packages/geoserver/layer.py", line 111, in _resolve_style
    return self.catalog.get_style_by_url(style_workspace_url)
  File "/usr/local/lib/python2.7/dist-packages/geoserver/catalog.py", line 798, in get_style_by_url
    dom = self.get_xml(style_workspace_url)
  File "/usr/local/lib/python2.7/dist-packages/geoserver/catalog.py", line 211, in get_xml
    response, content = self.http.request(rest_url)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1290, in _conn_request
    conn.connect()
  File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1060, in connect
    raise socket.error, msg

1 个答案:

答案 0 :(得分:1)

图片是否可公开阅读?如果是这样,你可以使用

<img src="http://<bucket>.storage.googleapis.com/<object>">

否则,您需要为GET操作生成signed URL,可以在图像标记中使用。