@web.removeslash
    def get(self, file_id=None):
        #
        # Get file (with given ID)
        #
        if not file_id:
            return self.json({
                'error': 'No file ID!',
                'time': round(self.request.request_time(), 3),
            }, 400)

        files = self.get_file(file_id=file_id, sharing_key=self.get_argument('key', default=None, strip=True))
        if not files:
            return self.json({
                'error': 'File with given ID is not found!',
                'time': round(self.request.request_time(), 3),
            }, 404)

        if files[0].get('url'):
            return self.redirect(files[0].get('url'))

        if files[0].get('s3key'):
            try:
                AWS_BUCKET     = self.app_settings('auth-s3', '\n', True).split('\n')[0]
                AWS_ACCESS_KEY = self.app_settings('auth-s3', '\n', True).split('\n')[1]
                AWS_SECRET_KEY = self.app_settings('auth-s3', '\n', True).split('\n')[2]
            except Exception, e:
                return self.json({
                    'error': 'Amazon S3 bucket, key or secret not set!',
                    'time': round(self.request.request_time(), 3),
                }, 400)
            s3_conn   = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY)
            s3_bucket = s3_conn.get_bucket(AWS_BUCKET, validate=False)
            s3_key    = s3_bucket.get_key(files[0].get('s3key'))
            if not s3_key:
                return self.json({
                    'error': 'File not found from Amazon S3!',
                    'time': round(self.request.request_time(), 3),
                }, 400)

            s3_url    = s3_key.generate_url(expires_in=3600, query_auth=True)
            return self.redirect(s3_url)

        if not files[0].get('file'):
            return self.json({
                'error': 'No file!',
                'time': round(self.request.request_time(), 3),
            }, 400)

        mimetypes.init()
        mime = mimetypes.types_map.get('.%s' % files[0].get('filename').lower().split('.')[-1], 'application/octet-stream')

        filename = files[0].get('filename')

        self.add_header('Content-Type', mime)
        self.add_header('Content-Disposition', 'inline; filename="%s"' % filename)
        self.write(files[0].get('file'))
dataset/ETHPy150Open argoroots/Entu/app/api/api2.py/API2File.get/original