java - Download link to CSV file in the mail using spring boot -
i generating csv in code, takes time generate. so, sending email link once csv file generated. when click that, getting 404 not found error. when have same link in html, able download it. insight or sample refer
sample link -http://localhost:9090/api/report/file?filename=filename.csv
java code download report
@requestmapping(value = "api/report/file") public void downloadcsv(httpservletresponse response, @requestparam("filename") string filename) throws ioexception { file file = new file(filename); inputstream = new fileinputstream(file); response.setcontenttype("application/octet-stream"); // response header response.setheader("content-disposition", "attachment; filename=\"" + file.getname() + "\""); // read file , write response outputstream os = response.getoutputstream(); byte[] buffer = new byte[1024]; int len; while ((len = is.read(buffer)) != -1) { os.write(buffer, 0, len); } os.flush(); os.close(); is.close(); }
Comments
Post a Comment