Skip to content

Commit 6807aa4

Browse files
echarrodzarembas
authored andcommitted
[SDK-160]: Added saving of image to Django example project
1 parent 9b50d3f commit 6807aa4

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@ ENV/
9494
*.un~
9595
.history/
9696
.vscode
97+
examples/yoti_example_django/yoti_example/static/YotiSelfie.jpg
9798
examples/yoti_example_django/db.sqlite3

examples/yoti_example_django/yoti_example/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,7 @@
120120
# https://docs.djangoproject.com/en/1.10/howto/static-files/
121121

122122
STATIC_URL = '/static/'
123+
STATICFILES_FOLDER_NAME = 'static'
124+
PROJECT_DIR = 'yoti_example/'
125+
STATIC_ROOT = os.path.join(BASE_DIR, STATICFILES_FOLDER_NAME)
126+
STATICFILES_DIRS = os.path.join(PROJECT_DIR, STATICFILES_FOLDER_NAME),

examples/yoti_example_django/yoti_example/templates/profile.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ <h3><a href="/">Home</a></h3>
1818
<tr>
1919
<td>SELFIE in base64 format:</td>
2020
<td><img width="200" alt="base64photo" src="{{selfie}}" /></td>
21-
</tr>
21+
</tr>
22+
<tr>
23+
<td>SELFIE from saved image:</td>
24+
<td><img width="200" alt="saved image" src="/static/YotiSelfie.jpg" /></td>
25+
</tr>
2226
{% endif %}
2327

2428
{% if given_names %}

examples/yoti_example_django/yoti_example/views.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import os
2+
13
from django.views.generic import TemplateView
24

35
from yoti_python_sdk import Client
6+
from binascii import a2b_base64
47

58
from .app_settings import (
69
YOTI_APPLICATION_ID,
@@ -23,4 +26,13 @@ def get(self, request, *args, **kwargs):
2326
client = Client(YOTI_CLIENT_SDK_ID, YOTI_FULL_KEY_FILE_PATH)
2427
activity_details = client.get_activity_details(request.GET['token'])
2528
context = activity_details.user_profile
29+
self.save_image(activity_details.user_profile.get('selfie'))
2630
return self.render_to_response(context)
31+
32+
@staticmethod
33+
def save_image(base64_uri):
34+
base64_data_stripped = base64_uri[base64_uri.find(",")+1:]
35+
binary_data = a2b_base64(base64_data_stripped)
36+
fd = open('yoti_example/static/YotiSelfie.jpg', 'wb')
37+
fd.write(binary_data)
38+
fd.close()

0 commit comments

Comments
 (0)