Esempio n. 1
0
def expose_blob_download(identifier,
                         expiry,
                         mimetype='text/plain',
                         content_disposition=None,
                         download_id=None):
    """
    Expose a blob object for download
    """
    # TODO add file parameter and refactor blob_db.put(...) into this method
    ref = BlobDownload(
        identifier,
        mimetype=mimetype,
        content_disposition=content_disposition,
        download_id=download_id,
    )
    ref.save(expiry)
    return ref
Esempio n. 2
0
def expose_blob_download(
        identifier,
        expiry,
        mimetype='text/plain',
        content_disposition=None,
        download_id=None):
    """
    Expose a blob object for download
    """
    # TODO add file parameter and refactor blob_db.put(...) into this method
    ref = BlobDownload(
        identifier,
        mimetype=mimetype,
        content_disposition=content_disposition,
        download_id=download_id,
    )
    ref.save(expiry)
    return ref
Esempio n. 3
0
    def test_expose_blob_download(self):
        ref = expose_blob_download(
            self.identifier,
            expiry=60,
            content_disposition='text/xml',
        )
        self.db.put(BytesIO(b'content'), meta=new_meta(key=ref.download_id))

        response = BlobDownload.get(ref.download_id).toHttpResponse()
        self.assertEqual(next(response.streaming_content), b'content')
Esempio n. 4
0
def expose_blob_download(identifier,
                         mimetype='text/plain',
                         content_disposition=None,
                         download_id=None):
    """
    Expose a blob object for download
    """
    ref = BlobDownload.create(
        identifier,
        mimetype=mimetype,
        content_disposition=content_disposition,
        download_id=download_id,
    )
    ref.save()
    return ref
Esempio n. 5
0
    def test_expose_blob_download(self):
        content_disposition = 'text/xml'
        download_id = 'abc123'

        self.db.put(StringIO(u'content'), self.identifier)

        expose_blob_download(self.identifier,
                             content_disposition=content_disposition,
                             download_id=download_id)

        download = BlobDownload.get(download_id)

        self.assertIsNotNone(download)

        response = download.toHttpResponse()
        self.assertEqual(next(response.streaming_content), u'content')
Esempio n. 6
0
    def test_expose_blob_download_with_legacy_download_id(self):
        self.db.put(BytesIO(b'legacy-blob'), self.identifier)

        ref = BlobDownload(
            self.identifier,
            mimetype='text/plain',
            content_disposition='text/xml',
        )
        ref.download_id = uuid4().hex  # old download id format
        ref.save(60)

        response = BlobDownload.get(ref.download_id).toHttpResponse()
        self.assertEqual(next(response.streaming_content), 'legacy-blob')