Skip to content

fix(file.controller.js): set headers for file extensions from MIME -I1218 #1330

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

Merged
merged 2 commits into from
Mar 27, 2020

Conversation

elit-altum
Copy link
Contributor

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • is from a uniquely-named feature branch and has been rebased on top of the latest master. (If I was asked to make more changes, I have made sure to rebase onto master then too)
  • is descriptively named and links to an issue number, i.e. Fixes #123

Fixes #1218

  • Adds mime-types as a dependency to check for the file's MIME and then set an appropriate header.

@elit-altum
Copy link
Contributor Author

@stalgiag Is this the right approach ? Please review!

@stalgiag
Copy link
Contributor

Hi @elit-altum one thing that I am noticing is that this is failing the linting test with the error Absolute imports should come before relative imports. Try moving up the import for mime-types.`

Other than that, this looks like it should work but I don't have the opportunity to test currently. Are you able to test successfully with the appropriate file types?

@elit-altum
Copy link
Contributor Author

Oh that's my bad @stalgiag. Thanks for pointing it out. I am really sorry
I tried logging the output of the return from mime.lookup and that seems to be working fine. But I am new to this so wanted a second opinion

@elit-altum elit-altum force-pushed the I1218-Changing-Content-Type branch from d5137e8 to 88e7214 Compare March 17, 2020 19:14
@andrewn
Copy link
Member

andrewn commented Mar 27, 2020

Thanks for opening this PR!

resolvedFile is an object, and mime.lookup() requires a filename string so I've changed this to resolvedFile.name.

Also, lookup() returns false if no mime-type is found, so I've added a fallback to application/octet-stream as recommended by the library otherwise the server crashes.

@andrewn andrewn merged commit 06bca99 into processing:master Mar 27, 2020
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.

Text assets's content-type is always text/html
3 participants