@GET('^/api/v1/get_image')
    @authenticated
    def get_image(self, request):
        @defer.inlineCallbacks
        def _showImage(resp=None):
            @defer.inlineCallbacks
            def _setContentDispositionAndSend(file_path, extension, content_type):
                request.setHeader('content-disposition', 'filename="%s.%s"' % (file_path, extension))
                request.setHeader('content-type', content_type)
                request.setHeader('cache-control', 'max-age=604800')

                f = open(file_path, "rb")
                yield FileSender().beginFileTransfer(f, request)
                f.close()
                defer.returnValue(0)

            if os.path.exists(image_path):
                yield _setContentDispositionAndSend(image_path, "jpg", "image/jpeg")
            else:
                request.setResponseCode(http.NOT_FOUND)
                request.write("No such image '%s'" % request.path)
            request.finish()

        if "hash" in request.args and len(request.args["hash"][0]) == 40:
            if self.db.filemap.get_file(request.args["hash"][0]) is not None:
                image_path = self.db.filemap.get_file(request.args["hash"][0])
            else:
                image_path = os.path.join(DATA_FOLDER, "cache", request.args["hash"][0])
            if not os.path.exists(image_path) and "guid" in request.args:
                node = None
                for connection in self.protocol.values():
                    if connection.handler.node is not None and \
                                    connection.handler.node.id == unhexlify(request.args["guid"][0]):
                        node = connection.handler.node
                        self.mserver.get_image(node, unhexlify(request.args["hash"][0])).addCallback(_showImage)
                if node is None:
                    _showImage()
            else:
                _showImage()
        else:
            request.write(NoResource().render(request))
            request.finish()

        return server.NOT_DONE_YET
dataset/ETHPy150Open OpenBazaar/OpenBazaar-Server/api/restapi.py/OpenBazaarAPI.get_image/original