Esempio n. 1
0
def test_upload_blob(test_bucket):
    with tempfile.NamedTemporaryFile() as source_file:
        source_file.write(b"test")

        storage_upload_file.upload_blob(
            test_bucket.name, source_file.name, "test_upload_blob"
        )
Esempio n. 2
0
def upload_dir(source, destination):
    arr = os.listdir(source)
    for item in arr:
        if (os.path.isfile(os.path.join(source, item))):
            storage_upload_file.upload_blob(constants.bucket_name,
                                            os.path.join(source, item),
                                            destination + item, 'image/webp')
            storage_make_public.make_blob_public(constants.bucket_name,
                                                 destination + item)
Esempio n. 3
0
def observation_ok(observation_key, observation, images, scales):

    i = 0
    for image in images:
        extension = image.filename[image.filename.rindex('.'):]
        filename = image.filename

        if '.jpg' != extension:
            image.save(filename.replace(extension, '.jpg'))
            storage_upload_file.upload_blob(constants.bucket_name, filename.replace(extension, '.jpg'),
                                            observation['photoPaths'][i].replace(extension, '.jpg'), 'image/jpeg')
            storage_make_public.make_blob_public(constants.bucket_name, observation['photoPaths'][i].replace(extension,
                                                                                                             '.jpg'))
        else:
            storage_make_public.make_blob_public(constants.bucket_name, observation['photoPaths'][i])

        size = min(image.width, image.height)
        image = utils.crop_square(image, size, size, scales[i])
        if size > 512:
            image = image.resize((512, 512), Image.ANTIALIAS)
        image.save(filename.replace(extension, '.webp'))
        storage_upload_file.upload_blob(constants.bucket_name, filename.replace(extension, '.webp'),
                                        observation['photoPaths'][i].replace(extension, '.webp'), 'image/webp')
        storage_make_public.make_blob_public(constants.bucket_name, observation['photoPaths'][i].replace(extension,
                                                                                                         '.webp'))
        i += 1
        image.close()

    observation['status'] = 'public'
    i = 0
    for path in observation['photoPaths']:
        extension = path[path.rindex('.'):]
        observation['photoPaths'][i] = observation['photoPaths'][i].replace(extension, '.webp')
        i += 1
    ref_public_by_date.child(observation_key).update(observation)
    ref_public_by_plant.child(observation['plant']).child('list').child(observation_key).update(observation)

    user = observation['id'][:observation['id'].index('_')]
    ref_private.child(user).child('by date').child('list').child(observation['id']).update(
        observation)
    ref_private.child(user).child('by plant').child(observation['plant']).child('list').child(
        observation['id']).update(observation)
    root.destroy()