Skip to content
Snippets Groups Projects
Commit 9808c6af authored by dw927's avatar dw927
Browse files

Getting images from s3 now through hard coding.

parent 7a9a03d8
Branches
No related tags found
No related merge requests found
...@@ -70,8 +70,9 @@ def post_file(request) : ...@@ -70,8 +70,9 @@ def post_file(request) :
return response return response
def image_name(image_url) : def image_name(image_url) :
image_name = image_url.split('/')[-1] print(image_url)
return image_name print(image_url.split('/')[-1])
return image_url.split('/')[-1]
def upload_service_url(image_url) : def upload_service_url(image_url) :
return image_url.replace('..', REPORTS_SERVICE_URL) return image_url.replace('..', REPORTS_SERVICE_URL)
...@@ -34,6 +34,7 @@ def get_reports() : ...@@ -34,6 +34,7 @@ def get_reports() :
@app.route(f'/{PREFIX}/report/<string:report_id>/images', methods=['GET']) @app.route(f'/{PREFIX}/report/<string:report_id>/images', methods=['GET'])
def get_images(report_id) : def get_images(report_id) :
provider = Provider() provider = Provider()
provider.download_images(report_id)
response = jsonify(provider.get_images(report_id)) response = jsonify(provider.get_images(report_id))
response.status_code = 200 response.status_code = 200
return response return response
...@@ -41,7 +42,7 @@ def get_images(report_id) : ...@@ -41,7 +42,7 @@ def get_images(report_id) :
@app.route(f'/{PREFIX}/report/<string:report_id>/image/<string:file_name>', methods=['GET']) @app.route(f'/{PREFIX}/report/<string:report_id>/image/<string:file_name>', methods=['GET'])
def get_image(report_id, file_name) : def get_image(report_id, file_name) :
provider = Provider() provider = Provider()
path = provider.get_image_path(file_name) path = provider.get_image_path(report_id, file_name)
return send_file( return send_file(
path, path,
download_name=file_name, download_name=file_name,
......
...@@ -2,6 +2,8 @@ import requests ...@@ -2,6 +2,8 @@ import requests
from PIL import Image from PIL import Image
import os import os
from base64 import b64encode from base64 import b64encode
import boto3
import glob
BASE_URL = 'http://127.0.0.1:5000' BASE_URL = 'http://127.0.0.1:5000'
SAVE_DIRECTORY = 'C:\\Users\\Dave\\OneDrive\\Documents\\Capstone\\data\\' SAVE_DIRECTORY = 'C:\\Users\\Dave\\OneDrive\\Documents\\Capstone\\data\\'
...@@ -21,17 +23,46 @@ class Provider: ...@@ -21,17 +23,46 @@ class Provider:
def get_reports(self): def get_reports(self):
url = BASE_URL + '/request_info' url = BASE_URL + '/request_info'
return requests.get(url).json() response = requests.get(url)
return response.json()
def get_images(self, report_id): def get_images(self, report_id):
report_id = 'fake_request_id'
save_chip_path = f'../dpath/report/{report_id}/image'
result = glob.glob(f'{save_chip_path}/*.png')[:50]
response = [] response = []
for _ in range(50) : for i in result:
response.append(f'../dpath/report/{report_id}/image/reportimage123.png') response.append(i.replace('\\', '/'))
return response return response
def get_image_path(self, image_name): def download_images(self, report_id) :
s3_client = boto3.client('s3')
s3_resource = boto3.resource('s3')
image_bucket = s3_resource.Bucket('digpath-predictions')
report_id = 'fake_request_id'
save_chip_path = f'../dpath/report/{report_id}/image'
dowloaded_files = glob.glob(f'{save_chip_path}/*.png')
prefix = f'{report_id}/severe_predictions/'
if not os.path.exists(save_chip_path):
os.makedirs(save_chip_path)
for s3_obj in image_bucket.objects.filter(Prefix=prefix):
if s3_obj.key == prefix:
continue
filename = s3_obj.key.split('/')[-1]
file_path = f'{save_chip_path}/{filename}'
if(file_path not in dowloaded_files) :
s3_client.download_file('digpath-predictions', s3_obj.key, file_path)
def get_image_path_old(self, image_name):
return SAVE_DIRECTORY + image_name return SAVE_DIRECTORY + image_name
def get_image_path(self, report_id, image_name) :
report_id = 'fake_request_id'
return f'{os.getcwd()}/../dpath/report/{report_id}/image/{image_name}'.replace('\\', '/')
def __save_local_file(self, file): def __save_local_file(self, file):
file_name = 'reportimage123.png' file_name = 'reportimage123.png'
new_file = open(SAVE_DIRECTORY + file_name, 'wb') new_file = open(SAVE_DIRECTORY + file_name, 'wb')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment