*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects

Fix InvenioRDM draft file upload

Merged Moser, Maximilian requested to merge mm/upload-fix into main
3 files
+ 20
9
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -144,14 +144,20 @@ class InvenioRDM(BaseWrapper):
try:
draft.get()
file_meta = FilesListMetadata([{"key": file_name}])
file = draft.files.create(file_meta)
stream = open(file_path, "rb")
for f in draft.files:
f.set_contents(OutgoingStream(data=stream))
f.commit()
return (record_pid, file.data["entries"][0]["key"])
files_list = draft.files.create(file_meta)
file = files_list(file_name)
with open(file_path, "rb") as stream:
# NOTE: The `OutgoingStream` constructor turns the keyword arguments
# into a dictionary which gets passed to `requests`, which
# then uses form-urlencoding rather than an octet-stream.
# To prevent this, we override the `_data` property.
out_stream = OutgoingStream()
out_stream._data = stream
file.set_contents(out_stream)
file.commit()
return (record_pid, file.data["key"])
except Exception as e:
print(f"File upload failed: {e}")
Loading