Ejemplo n.º 1
0
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:
    # Check that the access token is valid
Ejemplo n.º 2
0
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")