Skip to content

Commit

Permalink
Adding additional logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiehewitt15 committed Oct 10, 2023
1 parent 4b2b2fc commit 864df01
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/oceandbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,40 @@ def upload_files_to_ipfs(request_files, quote):
response = requests.post(url, files=file_data)
response.raise_for_status() # This will raise an error for HTTP error responses

print("Processing files from IPFS response...")

files = response.text.splitlines()
for file in files:
print("Processing files from IPFS response...")
added_file = {}
try:
json_version = json.loads(file)
except json.JSONDecodeError:
print(f"Error parsing IPFS response for file '{file}'. Invalid JSON received.")
continue

added_file['title'] = json_version['Name']
print(f"File '{added_file['title']}' uploaded successfully to IPFS. {json_version['Name']}")
added_file['cid'] = json_version['Hash']
added_file['public_url'] = f"https://ipfs.io/ipfs/{added_file['cid']}?filename={added_file['title']}"
added_file['length'] = json_version['Size']

content_type_retrieved = content_types.get(json_version['Name'], None)
if content_type_retrieved:
added_file['content_type'] = content_type_retrieved
else:
print(f"Warning: No content type found for file '{json_version['Name']}'. Using default.")
added_file['content_type'] = "application/octet-stream"

print(f"Saving file '{added_file['title']}' to the database...")
File.objects.create(quote=quote, **added_file)
print(f"File '{added_file['title']}' saved successfully to the database.")

files_reference.append({
"ipfs_uri": "ipfs://" + str(added_file['cid']),
"content_type": added_file['content_type']
})
print(f"Processed file '{added_file['title']}' with CID '{added_file['cid']}' and content type '{added_file['content_type']}'.")


except requests.RequestException as e:
print(f"HTTP error uploading to IPFS: {e}")
Expand Down

0 comments on commit 864df01

Please sign in to comment.