Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rest: change default mime type for files download #455

Merged
merged 1 commit into from
Jun 23, 2022

Conversation

mdonadoni
Copy link
Member

Changes the default MIME type used when downloading files to application/octet-stream.
Previously, multipart/form-data was used but the response was not correctly encoded as such.

Closes reanahub/reana-server#418

How to reproduce the issue:

  1. Launch reana-demo-helloworld
  2. Preview the file data/names.txt
  3. Check the logs of reana-server

Expected result: the warning is not present anymore in reana-server's logs

Changes the default MIME type used when downloading files to
`application/octet-stream`. Previously, `multipart/form-data` was used
but the response was not correctly encoded as such.

Closes reanahub/reana-server#418
Copy link

@VMois VMois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning disappeared.

minor: Looks like the return "Content-type" is always "application/octet-stream" for text, python, and JSON in web UI. Images and HTML files are fine. Not sure whether the client receives the same content type as web UI. It should use the same endpoint for downloading files.

Maybe, we should remove "application/json" from the OpenAPI spec if the JSON content-type is never returned.

@mdonadoni
Copy link
Member Author

mdonadoni commented Jun 16, 2022

minor: Looks like the return "Content-type" is always "application/octet-stream" for text, python, and JSON in web UI. Images and HTML files are fine. Not sure whether the client receives the same content type as web UI. It should use the same endpoint for downloading files.

Yes, even before these changes the content type was always multipart/form-data. However, in these cases (Python/JSON/text files) it might be better to use text/plain. Should we open an issue about this?

Maybe, we should remove "application/json" from the OpenAPI spec if the JSON content-type is never returned.

The application/json type is used when returning errors, for example:

except KeyError:
return jsonify({"message": "Malformed request."}), 400
except NotFound:
return jsonify({"message": "{0} does not exist.".format(file_name)}), 404
except Exception as e:
return jsonify({"message": str(e)}), 500

@VMois
Copy link

VMois commented Jun 16, 2022

However, in these cases (Python/JSON/text files) it might be better to use text/plain. Should we open an issue about this?

Let's open an issue not to lose track of it. I am not sure how important it is, but it doesn't break stuff so let's have an issue and deal with it later.

Copy link

@VMois VMois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR solves the issue. Nice work!

If you can create a minor issue to investigate/fix encoding type problems later (for text, py, and JSON files), that would be great.

@audrium audrium merged commit 8602d82 into reanahub:master Jun 23, 2022
@mdonadoni mdonadoni deleted the preview-mime-type branch October 13, 2022 14:02
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.

rest: warning when previewing files from UI
3 participants