<form name="write_form" enctype="multipart/form-data" method="post"action="fileUploader.asp" | |
Uploading using only One Page<p> | |
Select the file to upload : <input type="file"name="vodUploadForm"><p> | |
</form> | |
<input type="button" value="¾÷·Îµå"onClick="doUpload();"> | |
<script> | |
function doUpload(){ | |
document.write_form.submit(); | |
} | |
</script> 버튼 하나랑 텍스트 폼이 있는 페이지에 파일을 선택하고 버튼을 누르면 파일이 업로드 되는 페이지 소스입니다. <input type="file"name="vodUploadForm">에다가 동영상 파일 넣는건 됐는데... <input type="button" value="¾÷·Îµå"onClick="doUpload();"> 이걸 클릭 처리하는게 참.... 난감하군요 구글링 해봐도 관련 자료도 없고 참 ㅠㅠ 혹시나 해보신분들 있으시면 도움 부탁드리겠습니다... * 동영상 올리는건 HttpURLConnection으로 구현했습니다.
URL url = new URL(UPLOADER_URL); // open connection HttpURLConnection con = (HttpURLConnection)url.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); con.setRequestMethod("POST"); con.setRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); // write data DataOutputStream dos = new DataOutputStream(con.getOutputStream()); dos.writeBytes(hypen + boundary + CRLF); dos.writeBytes("Content-Disposition: form-data; name=\"vodUploadForm\";filename=\"" + URLEncoder.encode(params[0].getName()) + "\"" + CRLF); dos.writeBytes(CRLF); FileInputStream fileInputStream = new FileInputStream(params[0].getPath()); int bytesAvailable = fileInputStream.available(); int maxBufferSize = 1024; int bufferSize = Math.min(bytesAvailable, maxBufferSize); byte[] buffer = new byte[bufferSize]; int bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dos.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } dos.writeBytes(CRLF); dos.writeBytes(hypen + boundary + hypen + CRLF); dos.flush(); |