-
-
Notifications
You must be signed in to change notification settings - Fork 489
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
Attachments API use filename from Content-Disposition before url #8470
Attachments API use filename from Content-Disposition before url #8470
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested with some URL's and files from Google Drive, but Content-disposition is not set. I don't have access to OneDrive, but if you have tested, looks ok.
See the comment in the code.
return contentDisposition.split("filename=")[1].replace("\"", ""); | ||
} | ||
return null; | ||
} finally { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an exception occurs, should not be better to return null
, so it falls back to getFilenameFromUrl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, fixed in latest commit
I am having trouble finding a sample resource that uses Content-disposition other than on my own OneDrive but yes it is tested and works when the content disposition header is present. Also I fixed the issue you identified. |
…ileUrl.openConnection)
|
The backport to
stderr
stdout
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.2.x 4.2.x
# Navigate to the new working tree
cd .worktrees/backport-4.2.x
# Create a new branch
git switch --create backport-8470-to-4.2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick e5c788aaa20052d15f066fa73ab213c231ef30b7,cabdf0168c90aea78a71aaec340da515702e58d2,49af24534d997b7ca111799240cdf467c793a3f6,7794d7663ee3a14a479e57052a41601c3ce498e7,e040fab62c9c4a6ec9da935f8bfc73b7ea342b75,702b3ae671ed844c453ce065e52e970eee120e5e,77d5621e9b17871fd8e0b200e7c069a502961a14
# Push it to GitHub
git push --set-upstream origin backport-8470-to-4.2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.2.x Then, create a pull request where the |
…n before url (geonetwork#8470) * Update spring doc consumes and produces * Update putResource logic to get filename from contentDisposition header before using url * retrigger checks * retrigger checks * Remove incorrect consumes * Update getFilenameFromHeader to return null on exception * Update getFilenameFromHeader to return null on exception (including fileUrl.openConnection)
…n before url (#8470) (#8554) * Update spring doc consumes and produces * Update putResource logic to get filename from contentDisposition header before using url * retrigger checks * retrigger checks * Remove incorrect consumes * Update getFilenameFromHeader to return null on exception * Update getFilenameFromHeader to return null on exception (including fileUrl.openConnection) Co-authored-by: tylerjmchugh <[email protected]>
Currently the attachments
putResourceFromURL
API uses the last node from the URL (excluding query parameters) to get the filename. This becomes an issue when providing URL's that do not contain the filename in the last node. Instead the content disposition header should have higher priority over the url for retrieving the filename.For example when providing a URL for a file that is uploaded to a cloud provider like OneDrive the download URL looks like
.../.../download.aspx?...
. This means when putResourceFromUrl is called the extracted filename is alwaysdownload.aspx
rather than the actual file download's name. If content disposition is used instead the actual filename can be extracted from the header.Additionally there are some issues with the "consumes" and "produces" spring docs for
putResource
andputResourceFromURL
leading to an incorrect OpenAPI spec which causes the APIs to fail or return invalid responses. This also causes the swagger page to be incorrect and causes issues for codegen as the generated methods for putResource do not correctly provide the file asmultipart/form-data
.This should show that only multipart is accepted:
Issues with response codes because JSON is not defined as the return type (This call was successful):
This PR aims to fix these issues by first attempting to get the file name from the
Content-Disposition
header before falling back to the URL for the filename and by updating the spring docs.Checklist
main
branch, backports managed with labelREADME.md
filespom.xml
dependency management. Update build documentation with intended library use and library tutorials or documentation