def delete_file(): storage = Storage(client) print_green("Running Delete File API") result = storage.list_files() first_file_id = result['files'][0]['$id'] response = storage.delete_file(first_file_id) print(response)
def list_files(): storage = Storage(client) print_green("Running List Files API") result = storage.list_files() file_count = result['sum'] print("Total number of files {} ".format(file_count)) files = result['files'] print(files)
# Perform all your imports from appwrite.client import Client from appwrite.services.storage import Storage # Initialise the Appwrite client client = Client() client.set_endpoint('https://[HOSTNAME_OR_IP]/v1') # Your API Endpoint client.set_project('5df5acd0d48c2') # Your project ID client.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key # Initialise the sttorage SDK with the client object storage = Storage(client) # Perform your task result = storage.list_files()
# dependencies from appwrite.client import Client from appwrite.services.storage import Storage # Setup appwrite client client = Client() client.set_endpoint(os.environ['APPWRITE_ENDPOINT']) client.set_project(os.environ['APPWRITE_PROJECT_ID']) client.set_key(os.environ['APPWRITE_API_KEY']) # storage object for given client storage = Storage(client) # gather all files available in given storage result = storage.list_files(limit=100) # datetime objects to compare with time of files days = int(os.environ['DAYS_TO_EXPIRE']) delete_at = datetime.now() - timedelta(days=days) deleted_files = 0 # iterating over files in storage and deleting according constraints for each in result['files']: if each['dateCreated'] < delete_at.timestamp(): storage.delete_file(each['$id']) deleted_files += 1 print(f"Total files deleted: {deleted_files}")