gdcc / pyDataverse

Python module for Dataverse Software (dataverse.org).
http://pydataverse.readthedocs.io/
MIT License
64 stars 45 forks source link

Extract and supply file mimetype for `DataFile` upload #173

Closed JR-1991 closed 7 months ago

JR-1991 commented 8 months ago

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, the pyDataverse library was supplying text/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 to text/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's mimetypes library to predict the mimetype. Subsequently, the identified mime-type is passed to the request.post method. If the mime-type cannot be guessed, the method returns to the current implementation.

ToDos

Closes

Fixes #171