Hi there,
I am trying to upload files using REST API but for some reason, when I download these files, I see
a content-disposition header along with a number that is on top and bottom. Here's an example:
--3920b9ce37f4e3292af6d8081aa02501
1 Content-Disposition: form-data; name="file"; filename="TODO"
...file content...
--3920b9ce37f4e3292af6d8081aa02501--
I tried to send this with and without header, but regardless the outcome is same. I suspect that upon saving
these files, DSpace mistakenly adds this header to file content.
I tried to upload using python and bash, I'm adding the code snippets in case if they provide any useful information.
Python:
PARAMS = {'Accept': "application/json",
'Content-Type': "application/json"}
def upload_file(file_path, item_uuid, cookie):
""" Upload file to a DSpace item.
Arguments:
file -- The path of file to upload.
item_uuid -- The item UUID in the rest api.
cookie -- JSESSIONID for authentication.
"""
# Add JSESSIONID to request header
parameters = PARAMS
parameters["Cookie"] = "JSESSIONID=" + cookie
parameters["Content-Type"] = "multipart/form-data"
# Prepare files dict for request
file = open(file_path, 'rb')
files = {'file': file}
response = requests.post(url=URL + "/rest/items/" + item_uuid +"/bitstreams?name=" + os.path.basename(file.name),
files=files, headers=parameters)
pdb.set_trace()
file.close()
Bash:
Here's the information that you might need:
OS:
Manjaro Linux 19.0.2
Tomcat:
Server version: Apache Tomcat/8.5.51
Server built: Feb 5 2020 22:26:25 UTC
Server number: 8.5.51.0
OS Name: Linux
OS Version: 5.4.23-1-MANJARO
Architecture: amd64
JVM Version: 1.8.0_242-b08
JVM Vendor: Oracle Corporation
Maven:
Apache Maven 3.6.3 (NON-CANONICAL_2019-11-27T20:26:29Z_root)
Maven home: /opt/maven
Java version: 1.8.0_242, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.23-1-manjaro", arch: "amd64", family: "unix"
Ant:
Apache Ant(TM) version 1.10.7 compiled on September 10 2019
DSpace:
Any help would be appreciated ^_^