-
-
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
base: main
Are you sure you want to change the base?
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)
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