Create a file download link using Spring Boot and ThymeleafHow do I create a Java string from the contents of a file?How do I create a file and write to it in Java?How to create an HTML button that acts like a link?Download a file with Android, and showing the progress in a ProgressDialogDownloading a file from spring controllersHow to configure port for a Spring Boot applicationLogout link with Spring and ThymeleafCreating a file download link using Spring Boot and ThymeleafJava-Spring-JSP download xls file - POST OK, GET not workingActionlistener in Spring Boot and Thymeleaf
How can I detect if I'm in a subshell?
What could be the physiological mechanism for a biological Geiger counter?
Can a non-invertible function be inverted by returning a set of all possible solutions?
What is this plant I saw for sale at a Romanian farmer's market?
What is the color associated with lukewarm?
How to know whether to write accidentals as sharps or flats?
How can this shape perfectly cover a cube?
Digital signature that is only verifiable by one specific person
Fill the maze with a wall-following Snake until it gets stuck
How can a flywheel makes engine runs smoothly?
Catching a robber on one line
Co-worker is now managing my team. Does this mean that I'm being demoted?
What kind of chart is this?
How do I run a script as sudo at boot time on Ubuntu 18.04 Server?
High-end PC graphics circa 1990?
How to write a nice frame challenge?
Does anyone recognize these rockets, and their location?
Print the phrase "And she said, 'But that's his.'" using only the alphabet
Should I email my professor to clear up a (possibly very irrelevant) awkward misunderstanding?
How to address players struggling with simple controls?
How can Caller ID be faked?
Lead the way to this Literary Knight to its final “DESTINATION”
Having some issue with notation in a Hilbert space
Cut power on a remote Raspberry Pi 3 via another raspi
Create a file download link using Spring Boot and Thymeleaf
How do I create a Java string from the contents of a file?How do I create a file and write to it in Java?How to create an HTML button that acts like a link?Download a file with Android, and showing the progress in a ProgressDialogDownloading a file from spring controllersHow to configure port for a Spring Boot applicationLogout link with Spring and ThymeleafCreating a file download link using Spring Boot and ThymeleafJava-Spring-JSP download xls file - POST OK, GET not workingActionlistener in Spring Boot and Thymeleaf
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a download link on my page but it doesn't work and get error.
Here's my code.
request mapping :
@RequestMapping(value="/id/download", method=RequestMethod.GET)
public ResponseEntity<Resource> downloadFile(@PathVariable Integer id)
// Load file from database
MsFile file = null;
MsAnnouncement ano = null;
try
ano = anRepo.findById(id).get();
file = fileService.getFile(ano.getFileId().getId());
catch (Exception e)
// TODO Auto-generated catch block
e.printStackTrace();
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.getFileType()))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="" + file.getAttachedFileName() + """)
.body(new ByteArrayResource(file.getAttachedFile()));
html :
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/download/(id=$announcement.id)"
>Download</a>
I just need the file downloaded once when i click the button. But when i try with this code the file cannot be downloaded and get error at the return ResponseEntity.ok():
error following :
AnnouncementController.downloadFile(AnnouncementController.java:130) ~[classes/:na]
At java:130 :
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.getFileType()))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="" + file.getAttachedFileName() + """)
.body(new ByteArrayResource(file.getAttachedFile()));
}
java html spring-mvc thymeleaf
add a comment |
I have a download link on my page but it doesn't work and get error.
Here's my code.
request mapping :
@RequestMapping(value="/id/download", method=RequestMethod.GET)
public ResponseEntity<Resource> downloadFile(@PathVariable Integer id)
// Load file from database
MsFile file = null;
MsAnnouncement ano = null;
try
ano = anRepo.findById(id).get();
file = fileService.getFile(ano.getFileId().getId());
catch (Exception e)
// TODO Auto-generated catch block
e.printStackTrace();
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.getFileType()))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="" + file.getAttachedFileName() + """)
.body(new ByteArrayResource(file.getAttachedFile()));
html :
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/download/(id=$announcement.id)"
>Download</a>
I just need the file downloaded once when i click the button. But when i try with this code the file cannot be downloaded and get error at the return ResponseEntity.ok():
error following :
AnnouncementController.downloadFile(AnnouncementController.java:130) ~[classes/:na]
At java:130 :
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.getFileType()))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="" + file.getAttachedFileName() + """)
.body(new ByteArrayResource(file.getAttachedFile()));
}
java html spring-mvc thymeleaf
Please read minimal reproducible example and enhance your question accordingly. What error do you get?
– GhostCat
Mar 25 at 4:15
is the href correct on the html side?? Also are you able to download file via curl or postman.
– Grinish Nepal
Mar 25 at 4:22
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/dowload/(id=$announcement.id)"
The spelling of download is wrong.
– Vinay Avasthi
Mar 25 at 4:24
yes, i found it hhehehe just about the spelling :D
– deni maya
Mar 25 at 4:30
add a comment |
I have a download link on my page but it doesn't work and get error.
Here's my code.
request mapping :
@RequestMapping(value="/id/download", method=RequestMethod.GET)
public ResponseEntity<Resource> downloadFile(@PathVariable Integer id)
// Load file from database
MsFile file = null;
MsAnnouncement ano = null;
try
ano = anRepo.findById(id).get();
file = fileService.getFile(ano.getFileId().getId());
catch (Exception e)
// TODO Auto-generated catch block
e.printStackTrace();
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.getFileType()))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="" + file.getAttachedFileName() + """)
.body(new ByteArrayResource(file.getAttachedFile()));
html :
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/download/(id=$announcement.id)"
>Download</a>
I just need the file downloaded once when i click the button. But when i try with this code the file cannot be downloaded and get error at the return ResponseEntity.ok():
error following :
AnnouncementController.downloadFile(AnnouncementController.java:130) ~[classes/:na]
At java:130 :
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.getFileType()))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="" + file.getAttachedFileName() + """)
.body(new ByteArrayResource(file.getAttachedFile()));
}
java html spring-mvc thymeleaf
I have a download link on my page but it doesn't work and get error.
Here's my code.
request mapping :
@RequestMapping(value="/id/download", method=RequestMethod.GET)
public ResponseEntity<Resource> downloadFile(@PathVariable Integer id)
// Load file from database
MsFile file = null;
MsAnnouncement ano = null;
try
ano = anRepo.findById(id).get();
file = fileService.getFile(ano.getFileId().getId());
catch (Exception e)
// TODO Auto-generated catch block
e.printStackTrace();
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.getFileType()))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="" + file.getAttachedFileName() + """)
.body(new ByteArrayResource(file.getAttachedFile()));
html :
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/download/(id=$announcement.id)"
>Download</a>
I just need the file downloaded once when i click the button. But when i try with this code the file cannot be downloaded and get error at the return ResponseEntity.ok():
error following :
AnnouncementController.downloadFile(AnnouncementController.java:130) ~[classes/:na]
At java:130 :
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.getFileType()))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="" + file.getAttachedFileName() + """)
.body(new ByteArrayResource(file.getAttachedFile()));
}
java html spring-mvc thymeleaf
java html spring-mvc thymeleaf
edited Mar 25 at 4:28
deni maya
asked Mar 25 at 4:10
deni mayadeni maya
94
94
Please read minimal reproducible example and enhance your question accordingly. What error do you get?
– GhostCat
Mar 25 at 4:15
is the href correct on the html side?? Also are you able to download file via curl or postman.
– Grinish Nepal
Mar 25 at 4:22
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/dowload/(id=$announcement.id)"
The spelling of download is wrong.
– Vinay Avasthi
Mar 25 at 4:24
yes, i found it hhehehe just about the spelling :D
– deni maya
Mar 25 at 4:30
add a comment |
Please read minimal reproducible example and enhance your question accordingly. What error do you get?
– GhostCat
Mar 25 at 4:15
is the href correct on the html side?? Also are you able to download file via curl or postman.
– Grinish Nepal
Mar 25 at 4:22
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/dowload/(id=$announcement.id)"
The spelling of download is wrong.
– Vinay Avasthi
Mar 25 at 4:24
yes, i found it hhehehe just about the spelling :D
– deni maya
Mar 25 at 4:30
Please read minimal reproducible example and enhance your question accordingly. What error do you get?
– GhostCat
Mar 25 at 4:15
Please read minimal reproducible example and enhance your question accordingly. What error do you get?
– GhostCat
Mar 25 at 4:15
is the href correct on the html side?? Also are you able to download file via curl or postman.
– Grinish Nepal
Mar 25 at 4:22
is the href correct on the html side?? Also are you able to download file via curl or postman.
– Grinish Nepal
Mar 25 at 4:22
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/dowload/(id=$announcement.id)"
The spelling of download is wrong.– Vinay Avasthi
Mar 25 at 4:24
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/dowload/(id=$announcement.id)"
The spelling of download is wrong.– Vinay Avasthi
Mar 25 at 4:24
yes, i found it hhehehe just about the spelling :D
– deni maya
Mar 25 at 4:30
yes, i found it hhehehe just about the spelling :D
– deni maya
Mar 25 at 4:30
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331156%2fcreate-a-file-download-link-using-spring-boot-and-thymeleaf%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331156%2fcreate-a-file-download-link-using-spring-boot-and-thymeleaf%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please read minimal reproducible example and enhance your question accordingly. What error do you get?
– GhostCat
Mar 25 at 4:15
is the href correct on the html side?? Also are you able to download file via curl or postman.
– Grinish Nepal
Mar 25 at 4:22
<a class=" mx-1 btn btn-secondary" th:href="@/admin/announcement/id/dowload/(id=$announcement.id)"
The spelling of download is wrong.– Vinay Avasthi
Mar 25 at 4:24
yes, i found it hhehehe just about the spelling :D
– deni maya
Mar 25 at 4:30