def upload_file_to_storage(uid, field_id, date, source_file_name, destination_file_name, expire_minutes=15): from google.cloud import storage from oauth2client.service_account import ServiceAccountCredentials import os import firebase_admin from firebase_admin import credentials from firebase_admin import db import datetime try: cred = credentials.Certificate('servicekey.json') firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('initialized') source_url = source_file_name storage_client = storage.Client.from_service_account_json('servicekey.json') bucket_name = 'farmbase-b2f7e.appspot.com' destination_blob_name = 'PaidMonitoredFields/'+uid+'/'+field_id+'/'+date+'/' + destination_file_name bucket = storage_client.get_bucket(bucket_name) blob = bucket.blob(destination_blob_name) storage_url = 'https://farmonaut.com/Images/data_not_found.jpg' try: blob.upload_from_filename(source_url) storage_url = blob.generate_signed_url(version="v4",expiration = datetime.timedelta(minutes=expire_minutes), method="GET") except: print('not there') return storage_url