Skip to content

8344 file upload: default mime type #8392

Merged
kcondon merged 3 commits intodevelopfrom
8344-file-upload-default-mime
Mar 8, 2022
Merged

8344 file upload: default mime type #8392
kcondon merged 3 commits intodevelopfrom
8344-file-upload-default-mime

Conversation

@landreev
Copy link
Contributor

@landreev landreev commented Feb 2, 2022

see the issue.

What this PR does / why we need it:

Which issue(s) this PR closes:

Closes #8344

Special notes for your reviewer:

Suggestions on how to test this:

To reproduce the issue: try to upload a valid jpeg, exactly as shown below:

cat test.jpg | curl -H X-Dataverse-key:XXX -X POST -F "file=@-" -F 'jsonData={"label":"test_stream.jpg"}' http://localhost:8080/api/datasets/NNN/add

the file will upload, but will be identified as "text/plain". The PR should fix this.

Does this PR introduce a user interface change? If mockups are available, please link/include them here:

Is there a release notes update needed for this change?:

Additional documentation:

@landreev
Copy link
Contributor Author

testing slack activity feed. (@pdurbin)

@landreev landreev marked this pull request as ready for review March 3, 2022 16:19
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.001%) to 18.852% when pulling 8698f78 on 8344-file-upload-default-mime into ee7cc4b on develop.

@scolapasta scolapasta self-assigned this Mar 3, 2022
@scolapasta scolapasta removed their assignment Mar 3, 2022
@kcondon kcondon self-assigned this Mar 3, 2022
@kcondon
Copy link
Contributor

kcondon commented Mar 3, 2022

@landreev I can deploy due to a flyway conflict, does this pr need to be refreshed from develop?

@kcondon kcondon assigned landreev and unassigned kcondon Mar 4, 2022
@landreev
Copy link
Contributor Author

landreev commented Mar 7, 2022

Having looked into the reason this could not be easily reproduced on datavese-internal - my very first guess (shockingly!) appears to have been correct. The version of curl we have on the linux boxes is smarter than the one I have on my MacBook. It does actually send the default mime type header when called as described in my test scenario:

002c: Content-Disposition: form-data; name="file"; filename="-"
0067: Content-Type: application/octet-stream

... and that triggers the application to use the jhove-detected type, so the file ends up being properly typed as "image/jpeg".

To reiterate, the problem this PR was supposed to solve was not with curl. The problem was a file upload without a mime type header in the request. The curl line was just an easy way to produce such an upload that I knew of.

You should still be able to replicate it with curl, by going remotely from your own Macbook, like

cat some_valid.jpg | curl -k -H X-Dataverse-key:xxx -X POST -F "file=@-" -F 'jsonData={"label":"test_stream.jpg"}' https://dataverse-internal.iq.harvard.edu/api/datasets/NNNNN/add

(assuming your curl version is the same as mine; I would not count on it 100%)

Yet another way to test it would be using pyDataverse (that's how the issue was discovered; and that's the main use case I'm trying to fix). But then you'll have to mess with Python code, installing the module, etc.

@landreev landreev removed their assignment Mar 7, 2022
@kcondon kcondon self-assigned this Mar 8, 2022
@kcondon kcondon merged commit 1487650 into develop Mar 8, 2022
@kcondon kcondon deleted the 8344-file-upload-default-mime branch March 8, 2022 16:34
@pdurbin pdurbin added this to the 5.10 milestone Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File Upload API: problem with mime type detection

5 participants