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;








0















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()));
}









share|improve this question
























  • 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

















0















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()));
}









share|improve this question
























  • 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













0












0








0


0






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()));
}









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현