Comments (7)
Just tried in Safari on Mac and it is the same:
from spring-framework.
@mariuszpala something else must be going on than the code snippet you've shared as I am unable to reproduce what you've described. I can see the header as the one you've shared but the browser saves the file with the expected name for me, that is dev_document.xlsx
. Before we consider making a change, we need to understand the difference.
Please share a small sample we can run (not code in text) with instructions. I am also on Mac FWIW. Thanks.
from spring-framework.
OK, here is the more clear code snippet, I can prepare a complete sample app next week.
@RequestMapping(value = "/export", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
public ResponseEntity<Resource> exportToExcel() throws Exception {
String fileName = "dev_document.xlsx";
File xlsx = new File(fileName);
InputStreamResource resource = new InputStreamResource(new FileInputStream(xlsx));
String contentDisposition = ContentDisposition.attachment()
.filename(fileName, StandardCharsets.UTF_8)
.build()
.toString();
return ResponseEntity.ok()
.contentLength(xlsx.length())
.contentType(MediaType.parseMediaType(CONTENT_TYPE_XLSX))
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
.header(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION)
.body(resource);
}
from spring-framework.
That doesn't reproduce it either.
from spring-framework.
I am still unable to understand why I cannot reproduce it in a sample. I have exactly the same Spring Boot version, same endpoints returning same headers but it works from my sample, but doesn't work in our application.
@RequestMapping(value = "/export", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,produces = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
public ResponseEntity<Resource> exportToExcel() throws Exception {
String sourceFile = "dev_document.xlsx";
String fileName = "dev_document.xlsx";
File xlsx = new File(sourceFile);
InputStreamResource resource = new InputStreamResource(new FileInputStream(xlsx));
String contentDisposition = ContentDisposition.attachment()
.filename(fileName, StandardCharsets.UTF_8)
.build()
.toString();
return ResponseEntity.ok()
.contentLength(xlsx.length())
.contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
.header(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION)
.header("Strict-Transport-Security", "max-age=63072000; includeSubDomains; preload")
.header("Referrer-Policy", "same-origin")
.header("X-Content-Type-Options", "nosniff")
.header("X-Frame-Options", "SAMEORIGIN")
.header("Vary", "Origin")
.header("Vary", "Access-Control-Request-Method")
.header("Vary", "Access-Control-Request-Headers")
.body(resource);
}
This is the list of headers from my app where it's not working:
HTTP/1.1 200
Date: Thu, 28 Mar 2024 07:30:12 GMT
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Content-Length: 118326
Content-Disposition: attachment; filename="=?UTF-8?Q?dev=5Fdocument.xlsx?="; filename*=UTF-8''dev_document.xlsx
Connection: keep-alive
Referrer-Policy: same-origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Access-Control-Expose-Headers: Content-Disposition
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
And this is the list of response headers from the sample above when it's working:
HTTP/1.1 200
Date: Thu, 28 Mar 2024 07:27:02 GMT
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Content-Length: 16347
Content-Disposition: attachment; filename="=?UTF-8?Q?dev=5Fdocument.xlsx?="; filename*=UTF-8''dev_document.xlsx
Connection: keep-alive
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
Referrer-Policy: same-origin
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Access-Control-Expose-Headers: Content-Disposition
Keep-Alive: timeout=60
In both cases headers seem to be exactly the same, I will do more digging here because something is not right.
Any help appreciated though :)
from spring-framework.
Ticket can be closed, we found the issue was on the frontend side which incorrectly parsed the Content-Disposition header.
from spring-framework.
Thanks for letting us know
from spring-framework.
Related Issues (20)
- IllegalArgumentException / SpelEvaluationException even after compiling with -parameters HOT 1
- `@ContextConfiguration` does not merge duplicate sets of locations or classes within a test class hierarchy HOT 4
- org.springframework.web.socket.server.standard.SpringConfiguratorTests has a configuration class that scans itself
- Awaitility-based tests should wait more than one second
- ResponseStatusException thrown from exception handler methods is no longer respected HOT 5
- Consider adding support for resolving base64 encoded resources HOT 2
- @Named fails to instantiate dependency beans with type-mutating BPPs HOT 5
- Calling AOP annotated method with Kotlin Coroutines and parameter with private constructor causes IllegalAccessException in 6.1.5 HOT 2
- Remove unneeded `@SuppressWarnings("NullAway")` HOT 1
- Document that active profiles are set at build time with AOT HOT 9
- Indicate since what SF is possible declare @Transactional in an interface HOT 1
- @RequestBody decorator is crashing on Json.Parse for null types - null types are from Google Firebase response stream. HOT 1
- No support for SOAP webservices in 6.x HOT 1
- SpEL containing argument references not working from Spring boot 3.2.X and even after 3.2.3 HOT 3
- Remove unnecessary `method.isAccessible()` invocation
- Maximum Request Size handling support for Undertow in StandardMultipartHttpServletRequest HOT 1
- CoroutinesUtils causes ClassCastException & NullPointerException after upgrading to Spring 6.1.5 / Spring Boot 3.2.4 HOT 4
- MvcUriComponentsBuilder.fromMethodName does not pick the annotated method transparently HOT 6
- Support new Hooking Point. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-framework.