Extract and supply file mimetype for DataFile
upload
#173
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
In issue #171, it was reported that replacing data files was not working due to an incorrect mime-type being submitted. Specifically, when trying to replace a
docx
file, thepyDataverse
library was supplyingtext/plain
as the mime-type, which was causing the issue.It appears that this error originated from Python's
request
library, which was failing to supply the correct mime-type upon upload and was falling back totext/plain.
As a result, Dataverse rejected the replacement due to a different mime type being supplied than what already existed.In order to resolve the issue, the proposed solution involves extending the
post_request
and determining the mime-types before initiating a POST request. For this purpose, the implementation employs Python'smimetypes
library to predict the mimetype. Subsequently, the identified mime-type is passed to therequest.post
method. If the mime-type cannot be guessed, the method returns to the current implementation.ToDos
Closes
Fixes #171