class FileStackClient: logger = 'filestack' URL_API = 'https://www.filestackapi.com/api/file' def __init__(self, *args, **kwargs): self.client = Client(settings.FILESTACK_KEY) def log(self, msg, url, exception=None): logger.error('{}: {}-{}'.format(msg, url, getattr(exception, 'message', ''))) def get_video_info(self, resource): handle = resource.get_handle() url = '{}/{}/metadata'.format(self.URL_API, handle) return requests.get(url).json() def get_metadata(self, handle): url = '{}/{}/metadata'.format(self.URL_API, handle) return requests.get(url).json() def upload(self, filepath): return self.client.upload(filepath=filepath) def upload_png(self, filepath, intelligent=False): params = {'mimetype': 'image/png'} filelink = self.client.upload(filepath=filepath, params=params, intelligent=intelligent) return filelink def upload_url(self, url, intelligent=False): return self.client.upload_url(url=url) def get_url_screenshot(self, url, width, height): screenshot = self.client.urlscreenshot(external_url=url, width=width, height=height) try: filelink = screenshot.store() url = filelink.url except Exception as exception: self.log("FileStackClient.get_url_screenshot.Exception", url, exception) url = None return url def get_filelink_tags(self, filelink): return filelink.tags() def rotate_filelink(self, filelink, width, height, deg=90): transform = filelink.resize(width=width, height=height).rotate(deg=deg) new_filelink = transform.store() return new_filelink
def test_security_inheritance(upload_external_mock, multipart_mock): upload_external_mock.return_value = {'handle': 'URL_HANDLE'} multipart_mock.return_value = {'handle': 'FILE_HANDLE'} policy = {'expiry': 1900} cli = Client(APIKEY, security=Security(policy, 'SECRET')) flink_from_url = cli.upload_url('https://just.some/url') assert flink_from_url.handle == 'URL_HANDLE' assert flink_from_url.security.policy == policy flink = cli.upload(filepath='/dummy/path') assert flink.handle == 'FILE_HANDLE' assert flink.security.policy == policy
from filestack import Client, Security # policy expires on 5/6/2099 policy = {'call': ['read', 'remove', 'store'], 'expiry': 4081759876} security = Security(policy, '<YOUR_APP_SECRET>') client = Client(apikey='<YOUR_API_KEY>', security=security) filelink = client.upload_url(url='https://www.wbu.com/wp-content/uploads/2016/07/540x340-found-a-bird-450x283.jpg') filelink.delete()