Kew*_*sen 5 smb android jcifs image-uploading
当我100kb从平板电脑上传一张带有JCIFS的samba共享图片时,我遇到了一个问题,大概需要10-20分钟(在我更改缓冲区之前需要花费大约1024 to 209715206个小时)但是它不会产生任何影响来增加它
这不是连接问题,因为我已经测试了它ES File立即上载我的图片的位置
private class MyCopy extends AsyncTask<String, String, String> {
String z = "";
String username = "", password = "", servername = "", filestocopy = "";
@Override
protected void onPreExecute() {
username = edtusername.getText().toString();
password = edtpassword.getText().toString();
servername = "smb://" + edtservername.getText().toString();
filestocopy = editdir.getText().toString();
}
protected String doInBackground(String... params) {
// String buffer;
// buffer = setingPreferences.getString("buffer", "");
File file = new File(filestocopy);
String filename = file.getName();
NtlmPasswordAuthentication auth1 = new NtlmPasswordAuthentication(
servername, username, password);
try {
SmbFile sfile = new SmbFile(servername + "/" + filename, auth1);
if (!sfile.exists())
sfile.createNewFile();
sfile.connect();
InputStream in = new FileInputStream(file);
SmbFileOutputStream sfos = new SmbFileOutputStream(sfile);
byte[] buf = new byte[20971520]; //(parseInt(buffer))
int len;
while ((len = in.read(buf)) > 0){
sfos.write(buf, 0, len);
}
in.close();
sfos.close();
z = "File copied successfully";
} catch (Exception ex) {
z = z + " " + ex.getMessage().toString();
}
return z;
}
}
Run Code Online (Sandbox Code Playgroud)
缓冲区大小不应该产生明显的差异,但绝对不应该是 20M。请改用 4k 之类的东西。
您确定是实际的文件传输花费了这么长时间吗?100k 没有理由最多花费几秒钟。您是否尝试过在每个步骤之间放置日志语句,包括身份验证调用之前和之后,createNewFile()并connect()检查这些是否是瓶颈?
另外,我相信您应该在读取长度而>= 0不是严格复制字节时复制字节> 0,因为 -1 表示流的结束,而不是 0。
| 归档时间: |
|
| 查看次数: |
661 次 |
| 最近记录: |