def test_factory(self): """Test file factory function""" filename = self._get_file("txt") pk = FileModel.factory(filename).save().id() self.assertIsNotNone(pk) model = FileModel().load(pk) self.assertEqual(model.name(), os.path.basename(filename)) self.assertEqual(model.extension(), "txt") self.assertEqual(model.abspath(), os.path.dirname(os.path.abspath(filename)))
def test_factory(self): """Test file factory function""" filename = self._get_file('txt') pk = FileModel.factory(filename).save().id() self.assertIsNotNone(pk) model = FileModel().load(pk) self.assertEqual(model.name(), os.path.basename(filename)) self.assertEqual(model.extension(), 'txt') self.assertEqual(model.abspath(), os.path.dirname(os.path.abspath(filename)))
def file_stream_action(file_id=None, display_name=None): if not file_id: abort(404) model = FileModel().load(file_id) if not model.id(): abort(404) filename = '%s/%s' % (model.abspath(), model.name()) mimetype = '%s/%s' % (model.type(), model.subtype()) if not os.path.isfile(filename): abort(404) return Response(file(filename), direct_passthrough=True, content_type=mimetype)
def file_stream_action(file_id=None, display_name=None): if not file_id: abort(404) model = FileModel().load(file_id) if not model.id(): abort(404) filename = '%s/%s' % (model.abspath(), model.name()) mimetype = '%s/%s' % (model.type(), model.subtype()) if not os.path.isfile(filename): abort(404) return Response( file(filename), direct_passthrough=True, content_type=mimetype)