Exemplo n.º 1
0
def upload_picture(
    name
):  #uploads user picture to filestackcdn and returns a 500x500 img (FILESTACK API)
    client = Client('API KEY')

    filelink = client.upload(filepath='media/%s' % name)
    handle = Filelink(filelink.handle)
    new_filelink = handle.resize(width=500, height=500).store()
    return new_filelink.url  #return link of the new file uploaded (str)
Exemplo n.º 2
0
 def validate(self, data):
     file_handler = Filelink(data.get('filename'))
     try:
         users = self.get_users_from_filestack(file_handler)
     except Exception:
         raise exceptions.ValidationError('Incorrect format')
     return users
def test_apikey_default():
    filelink_default = Filelink(HANDLE)
    assert filelink_default.apikey is None
def secure_filelink():
    return Filelink(HANDLE, apikey=APIKEY, security=SECURITY)
def filelink():
    return Filelink(HANDLE, apikey=APIKEY)
Exemplo n.º 6
0
        SetVar(var_, id)

    except Exception as e:
        PrintException()
        raise Exception(e)

if module == "resize":

    id_ = GetParams('id_')
    width_ = GetParams('width_')
    height_ = GetParams('height_')
    check_ = GetParams('check_')
    var_ = GetParams('var_')

    try:
        filelink = Filelink(id_)

        if check_ == True:
            filelink = (
                # filelink.resize(width=width_, height=height_, fit="clip", align="top")
                filelink.resize(width=width_, height=height_,
                                fit="scale").store())

            id = os.path.basename(filelink.url)
            print(id)

        else:
            filelink = (filelink.resize(width=width_,
                                        height=height_,
                                        fit="clip").store())
            id = os.path.basename(filelink.url)
Exemplo n.º 7
0
 def update(self, fileID):
     Filelink(str(fileID)).download('./adms_user_db.npz')
Exemplo n.º 8
0
from filestack import security, Filelink

json_policy = {"expiry": 253381964415}

security = security(json_policy, '<YOUR_APP_SECRET>')

link = Filelink('YOUR_FILE_HANDLE', security=security)

# Storing is Only Allowed on Transform Objects
transform_obj = link.sepia()

new_link = transform_obj.store(filename='filename',
                               location='S3',
                               path='/py-test/',
                               container='filestack-test',
                               region='us-west-2',
                               access='public',
                               base64decode=True)

print(new_link.url)
Exemplo n.º 9
0
def secure_filelink():
    yield Filelink(HANDLE, apikey=APIKEY, security=SECURITY)
Exemplo n.º 10
0
def filelink():
    yield Filelink(HANDLE, apikey=APIKEY)
Exemplo n.º 11
0
def test_overwrite_with_file_obj(post_mock, secure_filelink):
    fobj = io.BytesIO(b'file-content')
    secure_filelink.overwrite(file_obj=fobj)
    post_mock.assert_called_once_with(
        'https://www.filestackapi.com/api/file/{}'.format(HANDLE),
        files={'fileUpload': ('filename', fobj, 'application/octet-stream')},
        params={
            'policy': SECURITY.policy_b64,
            'signature': SECURITY.signature,
            'base64decode': 'false'
        })


@pytest.mark.parametrize(
    'flink, exc_message',
    [(Filelink('handle', apikey=APIKEY), 'Security is required'),
     (Filelink('handle', security=SECURITY), 'Apikey is required')])
def test_delete_without_apikey_or_security(flink, exc_message):
    with pytest.raises(Exception, match=exc_message):
        flink.delete()


@pytest.mark.parametrize(
    'flink, security_arg',
    [(Filelink(HANDLE, apikey=APIKEY), SECURITY),
     (Filelink(HANDLE, apikey=APIKEY, security=SECURITY), None)])
@patch('filestack.models.filelink.requests.delete')
def test_successful_delete(delete_mock, flink, security_arg):
    flink.delete(security=security_arg)
    delete_mock.assert_called_once_with('{}/file/{}'.format(
        config.API_URL, HANDLE),
Exemplo n.º 12
0
from filestack import Filelink, security

# create security object
json_policy = {"YOUR_JSON": "POLICY"}

security = security(json_policy, '<YOUR_APP_SECRET>')

# initialize filelink object
filelink = Filelink('<YOUR_ALREADY_EXISTING_FILEHANDLE>',
                    apikey='<YOUR_APIKEY>',
                    security=security)

# overwrite file
filelink.overwrite(
    url=
    'https://images.unsplash.com/photo-1444005233317-7fb24f0da789?dpr=1&auto=format&fit=crop&w=1500&h=844&q=80&cs=tinysrgb&crop=&bg='
)

print(filelink.url)

# download file
filelink.download('</your/file/path/your_filename.filetype>')

# get filelink's metadata
response = filelink.get_metadata()
if response.ok:
    metadata = response.json()