Ejemplo n.º 1
0
    def _save(self, name, file) -> None:
        # TODO django 2.0: with file.open('wb') as f:
        file.open('rb')
        try:
            data = file.read()
        finally:
            file.close()

        content_type, _ = mimetypes.guess_type(name, strict=False)
        content_type = content_type or "application/octet-stream"

        metadata = {
            # These are static files, but only Webpack-generated files have
            # hashed filenames. Logos and whatnot don't. So let's tell the
            # browser to cache for one day, to time-bound the damage when we
            # deploy a new version of our logo and users keep the old one.
            'Cache-Control': 'public, max-age=86400',
        }

        if (
            content_type.startswith('text')
            or content_type.split('/')[1] in ('xml', 'json', 'javascript')
        ):
            data = gzip.compress(data)
            metadata['Content-Encoding'] = 'gzip'

        minio_client.put_object(StaticFilesBucket, name, io.BytesIO(data),
                                length=len(data), content_type=content_type,
                                metadata=metadata)
Ejemplo n.º 2
0
 def test_delete_deletes_from_s3(self):
     minio_client.put_object(StoredObjectsBucket,
                             'test.dat',
                             io.BytesIO(b'abcd'),
                             length=4)
     workflow = Workflow.objects.create()
     tab = workflow.tabs.create(position=0)
     wf_module = tab.wf_modules.create(order=0)
     so = wf_module.stored_objects.create(size=4,
                                          bucket=StoredObjectsBucket,
                                          key='test.dat',
                                          hash='123')
     so.delete()
     with self.assertRaises(error.NoSuchKey):
         minio_client.get_object(StoredObjectsBucket, 'test.dat')
    def _save(self, name, file) -> None:
        # TODO django 2.0: with file.open('wb') as f:
        file.open('rb')
        try:
            data = file.read()
        finally:
            file.close()

        content_type, _ = mimetypes.guess_type(name, strict=False)
        content_type = content_type or "application/octet-stream"

        metadata = {}

        if (content_type.startswith('text') or content_type.split('/')[1]
                in ('xml', 'json', 'javascript')):
            data = gzip.compress(data)
            metadata['Content-Encoding'] = 'gzip'

        minio_client.put_object(StaticFilesBucket,
                                name,
                                io.BytesIO(data),
                                length=len(data),
                                content_type=content_type,
                                metadata=metadata)