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)
def upload_file(): storage = Storage(client) print_green("Running Upload File API") response = storage.create_file( open("./nature.jpg", 'rb'), [], [] )
# 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()
FILENAME = "temp.jpg" # Triggered by the storage.files.create event payload = json.loads(os.environ["APPWRITE_FUNCTION_EVENT_DATA"]) fileID = payload["$id"] # Setup appwrite client client = Client() client.set_endpoint(os.environ["APPWRITE_ENDPOINT"]) client.set_project( os.environ["APPWRITE_FUNCTION_PROJECT_ID"]) # this is available by default client.set_key(os.environ["APPWRITE_API_KEY"]) # Get the image file storage = Storage(client) result = storage.get_file_preview(fileID) # Save the file to the container with open(FILENAME, "wb") as newFile: newFile.write(result) # Configure API key authorization: Apikey configuration = cloudmersive_image_api_client.Configuration() configuration.api_key['Apikey'] = os.environ['CLOUDMERSIVE_API_KEY'] # create an instance of the API class api_instance = cloudmersive_image_api_client.RecognizeApi( cloudmersive_image_api_client.ApiClient(configuration)) image_file = FILENAME # file | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
import json import os from appwrite.client import Client from appwrite.services.storage import Storage # Setup appwrite client client = Client() client.set_endpoint( os.environ["APPWRITE_ENDPOINT"]) # PRIVATE IP OF YOUR APPWRITE CONTAINER client.set_project(os.environ["APPWRITE_PROJECT"]) # YOUR PROJECT ID client.set_key(os.environ["APPWRITE_SECRET"]) storage = Storage(client) # result = storage.get_file(os.environ["APPWRITE_FILEID"]) print(os.environ["APPWRITE_FUNCTION_ID"]) print(os.environ["APPWRITE_FUNCTION_NAME"]) print(os.environ["APPWRITE_FUNCTION_TAG"]) print(os.environ["APPWRITE_FUNCTION_TRIGGER"]) print(os.environ["APPWRITE_FUNCTION_ENV_NAME"]) print(os.environ["APPWRITE_FUNCTION_ENV_VERSION"]) # print(result["$id"]) print(os.environ["APPWRITE_FUNCTION_EVENT"]) print(os.environ["APPWRITE_FUNCTION_EVENT_PAYLOAD"])
# general imports import os from datetime import datetime, timedelta # 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
TOKEN = os.environ['DROPBOX_KEY'] FILENAME = 'my-file.txt' BACKUPPATH = '/my-file.txt' # Setup the appwrite SDK client = Client() client.set_endpoint('http://192.168.1.6/v1') # Your API Endpoint client.set_project('5fca866c65afc') # Your project ID client.set_key(os.environ["APPWRITE_KEY"]) # Your secret API key # Get the ID of the uploaded file from the environment variable set by appwrite. payload = json.loads(os.environ["APPWRITE_FUNCTION_EVENT_PAYLOAD"]) fileID = payload["$id"] # Create an instance of Appwrite's Storage API storage = Storage(client) result = storage.get_file_download(fileID) # Save the file to the container with open(FILENAME, "wb") as newFile: newFile.write(result) # Check if we have the access token if (len(TOKEN) == 0): sys.exit("ERROR: Looks like you didn't add your access token. " "Open up backup-and-restore-example.py in a text editor and " "paste in your token in line 14.") # Create an instance of a Dropbox class, which can make requests to the API. print("Creating a Dropbox object...") with dropbox.Dropbox(TOKEN) as dbx:
from appwrite.client import Client from appwrite.services.storage import Storage import io import PIL.Image as Image from secret_key import SECRET_KEY from project_data import PROJECT_ID, ENDPOINT_URL, FILE_ID client = Client() (client.set_endpoint(ENDPOINT_URL) # Your API Endpoint .set_project(PROJECT_ID) # Your project ID .set_key(SECRET_KEY) # Your secret API key ) storage = Storage(client) result = storage.get_file(FILE_ID) result = storage.get_file_download(FILE_ID) print(type(result)) if (isinstance(result, bytes)): image = Image.open(io.BytesIO(result)) image.save("./image.png")
def backup(id): FileName = "data_file-" + id + ".csv" os.rename(PATH1, FileName) storage = Storage(client) result_upload = storage.create_file(open(FileName, 'rb'))
def send_image(): storage = Storage(client) result = storage.create_file(open('optimized.png', 'rb'))