NAS에서 파일을 받아야 합니다.


보안 때문에 직접 url 처리로 다운 받지는 못하고 spring의 .do 액션을 이용하여 다운을 받아야 합니다.


web에선 


String mimetype = "application/x-msdownload";


response.setContentType(mimetype);

setDisposition(fvo.getOrignlFileNm(), request, response);

response.setContentLength(fSize);


in = new BufferedInputStream(new FileInputStream(uFile));

out = new BufferedOutputStream(response.getOutputStream());


FileCopyUtils.copy(in, out);

out.flush();


해당 부분을 이용하여 파일을 다운로드 할 수 있도록 하였고


웹 브라우저 및 모바일용 브라우저에서도 다운로드가 잘 됨을 확인 하였습니다.


문제는 안드로이드 웹뷰에서 다운로드가 안되는 것입니다.


빌트인 브라우저에서 구동할 경우 url로 액션을 읽어 처리하는 방식 때문에 0byte의 파일만을 만들어 낸다는 것이 가장 큰 문제입니다.


해당 부분은 안드로이드 웹뷰의 downloadListener의 부분입니다.


mWebView.setDownloadListener(new DownloadListener(){

public void onDownloadStart(String url, String sUserAgent, String contentDisposition, String mimetype, long contentLength) {

URL urls = null;

String fileUrl = "";

String mPath = "";

Log.v("sUserAgent", sUserAgent);

String condition[] = contentDisposition.split("=");

String x = condition[1];

try {

fileUrl = URLDecoder.decode(x, "UTF-8");

} catch(Exception e) {

e.printStackTrace();

}

try {

urls = new URL("url);

} catch (MalformedURLException e) {

e.printStackTrace();

}

String fileName[] = url.split("/");

Log.d("test", url);

try {

HttpURLConnection conn= (HttpURLConnection)urls.openConnection();

conn.setDoOutput(true);

conn.connect();

mPath = Environment.getExternalStorageDirectory()+"/Download/";

String chkPath = Environment.getExternalStorageDirectory()+"/Download/"+fileUrl;

File chkFile = new File(chkPath);

if(chkFile.exists() == true){}

else {

File f = new File(mPath);

f.mkdirs();

File OutputFile = new File(f, fileUrl);

FileOutputStream fos = new FileOutputStream(OutputFile);

InputStream is = conn.getInputStream();

byte[]buffer = new byte[24576];

int len1 = 0;


while((len1 = is.read(buffer)) != -1) {

fos.write(buffer, 0, len1);

}

fos.close();

is.close();

}

} catch (IOException e) {

e.printStackTrace();

}

Toast.makeText(getApplicationContext(), "다운로드 완료", 0).show();

File files = new File(mPath+fileUrl);

Log.e("msg",mPath+fileUrl+"");

Intent intent = new Intent(Intent.ACTION_VIEW);

String mimes = fileUrl.substring(fileUrl.length()-3, fileUrl.length());

if(mimes.equals("hwp")) {

intent.setDataAndType(Uri.fromFile(files), "application/x-hwp");

} else {

intent.setDataAndType(Uri.fromFile(files), "application/"+mimes);

}

startActivity(intent);

}

        });


만일 web쪽에서 response 객체에 i/o 타입 혹은 기타 방식으로 파일을 집어넣을 수 있는지 방법이 궁금하고


가능하다면 webview 부분에선 어떻게 처리하여야 파일을 다운로드 할 수 있는지 문의 드립니다.