Exemple #1
0
def file_upload(path_to_file='attachments/', filename='default_name'):
    # Enable Storage
    client = storage.Client()

    # Reference an existing bucket.
    bucket = client.get_bucket('mcc-fall-2019-g5-258415.appspot.com')

    # Upload a local file to a new file to be created in your bucket.
    tmpBlob = bucket.blob(path_to_file + filename)
    tmpBlob.upload_from_filename(filename='img/{}'.format(filename))
Exemple #2
0
def file_download(filepath='attachments/', filename='default_name'):
    # Enable Storage
    client = storage.Client()

    # Reference an existing bucket.
    bucket = client.get_bucket('mcc-fall-2019-g5-258415.appspot.com')

    print(filepath)

    tmpBlob = bucket.blob(filepath)
    tmpBlob.download_to_filename('tmp/' + filename)
Exemple #3
0
def image_download(path_to_file='attachments/',
                   filename='default_name',
                   quality='best_quality'):
    # Enable Storage
    client = storage.Client()

    # Reference an existing bucket.
    bucket = client.get_bucket('mcc-fall-2019-g5-258415.appspot.com')

    if quality == 'middle_quality':
        tmpBlob = bucket.blob(path_to_file + filename + 'middle_quality')

    elif quality == 'low_quality':
        tmpBlob = bucket.blob(path_to_file + filename + 'low_quality')

    else:
        tmpBlob = bucket.blob(path_to_file + filename + 'best_quality')

    tmpBlob.download_to_filename(filename)
Exemple #4
0
def image_upload(source_dir='img/',
                 dest_fb_dir='attachments/',
                 filenames=['default_name']):
    '''
    Upload resized images to server.
    '''

    try:
        # Enable Storage
        client = storage.Client()

        # Reference an existing bucket.
        bucket = client.get_bucket('mcc-fall-2019-g5-258415.appspot.com')

        for filename in filenames:
            tmpBlob = bucket.blob(dest_fb_dir + filename)
            tmpBlob.upload_from_filename(filename=source_dir + filename)

        return True

    except:
        return False
Exemple #5
0
def image_upload(path_to_file='attachments/', filename='default_name'):
    # Enable Storage
    client = storage.Client()

    # Reference an existing bucket.
    bucket = client.get_bucket('mcc-fall-2019-g5-258415.appspot.com')

    im = Image.open('img/{}'.format(filename))
    low_q = Image.new('RGB', im.size, (255, 255, 255))
    low_q.paste(im, (0, 0), im)
    low_q.save('img/low_quality.png', quality=40)

    mid_q = Image.new('RGB', im.size, (255, 255, 255))
    mid_q.paste(im, (0, 0), im)
    mid_q.save('img/middle_quality.png', quality=70)

    tmpBlob = bucket.blob(path_to_file + filename + '/best_quality')
    tmpBlob.upload_from_filename(filename='img/{}'.format(filename))

    tmpBlob = bucket.blob(path_to_file + filename + '/middle_quality')
    tmpBlob.upload_from_filename(filename='img/middle_quality.png')

    tmpBlob = bucket.blob(path_to_file + filename + '/low_quality')
    tmpBlob.upload_from_filename(filename='img/low_quality.png')