2012-01-19 2 views
1

내 업로드 방법 :얼마나 많은 바이트가 지금까지 업로드 되었습니까? 아래

private void upload(String Server, String FilePath, String SavePath, String NewName) { 
String end = "\r\n"; 
String twoHyphens = "--"; 
String boundary = "*****"; 
try { 
URL url = new URL(ActionUrl); 
HttpURLConnection con = (HttpURLConnection) url.openConnection(); 
con.setDoInput(true); 
con.setDoOutput(true); 
con.setUseCaches(false); 
con.setRequestMethod("POST"); 
con.setRequestProperty("Connection", "Keep-Alive"); 
con.setRequestProperty("Accept", "text/*"); 
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); 
ds = new DataOutputStream(con.getOutputStream()); 
ds.writeBytes(twoHyphens + boundary + end); 
ds.writeBytes("Content-Disposition: form-data;" + "name=\"folder\"" + end + end); 
ds.write(SavePath.getBytes("UTF-8")); 
ds.writeBytes(end); 
ds.writeBytes(twoHyphens + boundary + end); 
ds.writeBytes("Content-Disposition: form-data;" + "name=\"Filedata\"; filename=\""); 
ds.write(NewName.getBytes("UTF-8")); 
ds.writeBytes("\"" + end); 
ds.writeBytes(end); 

FileInputStream fStream = new FileInputStream(uploadFile); 
int bufferSize = 1024; 
byte[] buffer = new byte[bufferSize]; 
int length = -1; 
while((length = fStream.read(buffer)) != -1) { 
ds.write(buffer, 0, length); 
}  
ds.writeBytes(end); 
ds.writeBytes(twoHyphens + boundary + twoHyphens + end); 

fStream.close(); 
ds.flush(); 
InputStream is = con.getInputStream(); 
int ch; 
StringBuffer b = new StringBuffer(); 
while((ch = is.read()) != -1) { 
b.append((char)ch); 
} 
System.out.println("UPLOAD" + "SUCCESS"); 
ds.close(); 
} 
catch(Exception e) { 
e.printStackTrace(); 
} 
} 

나는 진행률 표시 줄을 표시합니다. 하지만 지금까지 얼마나 많은 바이트가 업로드되었는지 알지 못했습니다. 업로드 할 바이트 수를 얻는 방법은 무엇입니까?

답변

1

내가 어떻게 java.So에서이 작업을 수행하려면 안드로이드와 행운을 시도하고 아래 링크를 ------------- Uploading code

날 know.Follow하자 그것을 알고입니다 어떤 이론 설명

SecondLink

관련 문제