from tkinter import * from PIL import ImageTk,Image from PIL.ExifTags import TAGS import io import dropbox import base64 import requests import json def print_response(response): print("Code: " + str(response.status_code) + "; Body: " + str(response.json())) def show_image(pil_image): root = Tk() canvas = Canvas(root, width = pil_image.size[0], height = pil_image.size[1]) canvas.pack() img = ImageTk.PhotoImage(pil_image) canvas.create_image(20, 20, anchor=NW, image=img) root.mainloop() def print_metadata(pil_image): exifdata = pil_image.getexif() print("found " + str(len(exifdata)) + " metadata tags") for tag_id in exifdata: # get the tag name, instead of human unreadable tag id tag = TAGS.get(tag_id, tag_id) data = exifdata.get(tag_id) # decode bytes if isinstance(data, bytes): data = data.decode() print(f"{tag:25}: {data}") #path = "bild_mit_metadaten" + ".jpg" path = "bild_ohne_metadaten2" + ".jpg" im = Image.open(path) #show_image(im) #print_metadata(im) global b64_file with open(path, "rb") as image_file: b64_file = base64.b64encode(image_file.read()) payload = b64_file.decode('utf-8') #Bild lokal encoden (spiel Server zum testen) #encoded_bytes = payload.encode('utf-8') #decoded_file = base64.b64decode(encoded_bytes) #img2 = Image.open(io.BytesIO(decoded_file)) #show_image(img2) #print_metadata(img2) #dbx = dropbox.Dropbox('SDt1aqMQg7EAAAAAAAAAARV4CNnOSTjYLc05W2YAxIArG93DnaK9Si9VbwE-aBbQ') #dbx.files_upload(decoded_file,'/Apps/AIC Federated Storage Infrastructure/test_image_1.jpg') baseurl = "http://127.0.0.1:8000/image/post" session = requests.Session() body = { 'filename': 'image.jpg', 'metadata': 'nix', 'image_data': payload } response = session.post(baseurl, json=body) print_response(response)