ローカル サーバ内のファイル サイズを返す JSP コード。jquery.file.size-extension.js と組み合わせて使用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="WINDOWS-31J" %> | |
<% | |
//ローカル サーバ内のファイル サイズを返す | |
String callbackFunc = request.getParameter("callback"); | |
String DOWNLOAD_FILE_URL = request.getParameter("url"); | |
try { | |
java.net.URL url = new java.net.URL (DOWNLOAD_FILE_URL); | |
java.lang.String root = "/http_root_dir/"; //URLのルートにあたるサーバのローカル ディレクトリ | |
java.lang.String path = url.getPath(); | |
java.lang.String path = root + path; | |
java.io.FileInputStream file = new java.io.FileInputStream(path); | |
int file_size = file.available(); | |
file.close(); | |
out.println(callbackFunc + "({size:\"" + file_size + "\"});"); | |
// //URLクラスでアクセスする方法だと認証が必用なディレクトリのサイズが取得できない | |
// java.net.HttpURLConnection httpURLConnection = (java.net.HttpURLConnection) url . openConnection (); | |
// | |
// httpURLConnection . setRequestMethod ("HEAD"); | |
// httpURLConnection . connect (); | |
// if( httpURLConnection . getResponseCode () == 200 ) { | |
// out.println(callbackFunc + "({size:\"" + httpURLConnection . getContentLength () + "\"});"); | |
// } | |
// else { | |
// out.println(callbackFunc + "({size:\"" + -1 + "\"});"); | |
// } | |
} | |
catch (IOException e) { | |
out.println(callbackFunc + "({size:\"" + -99 + "\"});"); | |
} | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment