Skip to content

Commit

Permalink
Merge pull request #97 from oceanprotocol/content-type-fix
Browse files Browse the repository at this point in the history
Content type fix
  • Loading branch information
jamiehewitt15 authored Oct 10, 2023
2 parents 40171ad + b9b6901 commit 1bd5715
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 0 additions & 2 deletions server/oceandbs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class File(models.Model):
cid = models.CharField(max_length=2048, null=True)
quote = models.ForeignKey(Quote, null=True, on_delete=models.SET_NULL, related_name="files")
length = models.BigIntegerField(default=0)
content_type = models.CharField(max_length=255, null=True, blank=True)


def __str__(self):
return str(self.quote) + " - " + str(self.length)
13 changes: 3 additions & 10 deletions server/oceandbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,16 @@ def upload_files_to_ipfs(request_files, quote):
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"Content type for file '{added_file['title']}' is '{content_type_retrieved}'.")
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']
"content_type": content_type_retrieved
})
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}")
raise ValueError(f"HTTP error uploading to IPFS: {e}")
Expand Down

0 comments on commit 1bd5715

Please sign in to comment.