本地图片上传到远程目录。大概2M
有时候 只上传几十Kb,显示一部分的图片。
不知道是网络的原因,还是我的代码问题
//path:远程路径 user:用户 pwd:密码 localFile:本地文件 fileName:文件名
public boolean saveSamba(String path, String user, String pwd, File localFile, String fileName) {
try {
String url = path + fileName;
SmbFile file = null;
try {
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,user,pwd);
file = new SmbFile(url, auth);
Log.d("SambaUtil",url);
FileInputStream input = new FileInputStream(localFile);
SmbFileOutputStream out = new SmbFileOutputStream(file);
byte bytes[] = new byte[1024];
int temp=0;
while ((temp=input.read(bytes))!=-1) {
out.write(bytes,0,temp);
}
out.flush();
out.close();
input.close();
System.out.println("文件上传成功");
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}