IoT Client und Changes vom Herzeigen

This commit is contained in:
Martin Schett 2020-11-26 19:15:46 +01:00
parent 31899ebd64
commit e4b40133eb
31 changed files with 86 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

78
iotclient/client.py Normal file
View File

@ -0,0 +1,78 @@
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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

0
logfile Normal file
View File

View File

@ -219,4 +219,4 @@ LOGGING = {
# increase the maximum upload size of files
DATA_UPLOAD_MAX_MEMORY_SIZE = 104857600
DROPBOX_OAUTH2_ACCESS_TOKEN = 'sl.AmBKKaIkaH0ZKuk5i60EbN8dIspDugFK2k4ixfMkr3BZ7ZJ0yF5YAj-69mWKO-G_K-ctk_Ai4a6BeOXEZ_kZH4waUUlPhnV3QBe4QfGYN5PQcs-9SwQ5BWQfeQSKw9jkybbV9mjOdQ4'
DROPBOX_OAUTH2_ACCESS_TOKEN = 'SDt1aqMQg7EAAAAAAAAAARV4CNnOSTjYLc05W2YAxIArG93DnaK9Si9VbwE-aBbQ'

View File

@ -37,7 +37,11 @@ class ImageEndpoint:
@api_view(['POST'])
def image_api_post(request: HttpRequest):
logger.debug('Image POST call: {}'.format(request))
data = json.loads(request.body.decode('utf-8'))
payload = json.loads(request.body.decode('utf-8'))
b64encoded_image = payload['image_data']
filename = payload['filename']
metadata = payload['metadata']
decoded_image = base64.b64decode(b64encoded_image)
dbx = dropbox.Dropbox(settings.DROPBOX_OAUTH2_ACCESS_TOKEN)
dbx.files_upload(base64.b64decode(data['image_data']),'/Apps/AIC Federated Storage Infrastructure/test_image_1.jpg')
return JsonResponse({'Result': 'success2', 'received file': data['filename']}, safe=False)
dbx.files_upload(decoded_image,'/Apps/AIC Federated Storage Infrastructure/' + filename)
return JsonResponse({'Result': 'success2', 'received file': filename, 'metadata': metadata}, safe=False)

View File

@ -19,7 +19,6 @@ setup(
'whitenoise==5.2.0',
'Pillow==8.0.1',
'dropbox==10.10.0'
],
license='BSD License', # example license
description='DESCRIPTION'