nginx 아래 전단 크로스 도 메 인 다운로드 파일
@RequestMapping(value = "url", method = RequestMethod.GET)
public void downloadEdiFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
String mainUrl = request.getParameter("fileUrl");// , 、 、token
String fileUrl = mainUrl.substring(mainUrl.indexOf("/"),mainUrl.indexOf("?"));//
String mianFileName = mainUrl.substring(0,mainUrl.indexOf("/"));//
String fileExtension = fileUrl.substring(fileUrl.lastIndexOf("."));//
String fileName = mianFileName+fileExtension;// ( )
//
String filePath = "http://112.112.223.229:1013/fileload" + fileUrl;
//
URL url = new URL(filePath);
URLConnection conn = url.openConnection();
InputStream txtIn = conn.getInputStream();
//
// InputStream txtIn = new FileInputStream(new File(filePath));
OutputStream os = response.getOutputStream();
String userAgent = request.getHeader("user-agent").toLowerCase();
if (userAgent.contains("msie") || userAgent.contains("like gecko")) {
// win10 ie edge ie
fileName = URLEncoder.encode(fileName, "UTF-8");
} else {
//
fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
}
response.setContentType("application/octet-stream; charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);// @TODO
//
byte[] bytes = new byte[1024];
//
int len = 0;
while ((len = txtIn.read(bytes)) > 0) {
os.write(bytes, 0, len);
}
if (os!=null){
os.close();
}
if (txtIn!=null){
txtIn.close();
}
}
token 과 fileName 을 연결 하 는 간단 한 연결 경로 입 니 다.
html js 코드
//
$(document).on('click', '.upload-btn', function () {
var fileUrl = $(this).parent().parent().siblings("td[data-field='fileUrl']").children()[0].innerHTML;
var fileName = $(this).parent().parent().siblings("td[data-field='fileName']").children()[0].innerHTML;
if (fileName === null || fileName.length === 0) {
fileName = radioData.procPlanName + "-" + ($(this).parent().parent().siblings("td[data-field='procRecipeName']").children()[0].innerText);
}
//fileUrl ;fileName
downloadFile(fileUrl, fileName);
});
//form , , ; , iframe , target=\"mangguo\"
function iframeFileFlag() {
if (iframeFlag === false) {
iframeFlag = true;
alert(" ");
}
}
//
function downloadFile(fileUrl, fileName) {
iframeFlag = false;
var $downForm = $("
html
<button type="button" class="layui-btn upload-btn"><i class="layui-icon"></i> </button>
<iframe name="mangguo" style="display: none" onload="iframeFileFlag()"></iframe>
ps: 코드 는 한 네티즌 의 답 을 참고 했다.그런데 그 화면 을 못 찾 겠 어 요. 감사합니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 파일 다운로드의 몇 가지 실현 방식을 상세히 설명하다Java 파일을 다운로드하는 방법은 다음과 같습니다. //파일을 온라인으로 열 수 있는 방법 이상은 본문의 전체 내용입니다. 여러분의 학습에 도움이 되고 저희를 많이 응원해 주십시오....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.