我想使用NAS server
将图像文件(jpg,png)发送到java中的smb我添加了jcifs-1.3.19.jar。如上所述here和here
编辑:我已经使用此代码成功将jpeg图像发送到服务器上的共享文件夹,但速度非常慢,其发送速度接近1kb /秒。任何解决方案??
const http = require('http');
const url = require('url');
const fibonacciAsync = exports.fibonacciAsync = (n, done) => {
if (n === 1 || n === 2) {
done(1);
} else {
process.nextTick(() => {
fibonacciAsync(n - 1, (val1) => {
process.nextTick(() => {
fibonacciAsync(n - 2, (val2) => {
done(val1 + val2);
})
})
})
})
}
}
http.createServer((req, res) => {
const urlP = url.parse(req.url, true);
let fibo;
res.writeHead(200, {'Content-Type': 'text/plain'});
if (urlP.query['n']) {
fibo = fibonacciAsync(urlP.query['n']);
res.end('Fibonacci ' + urlP.query['n'] + '=' + fibo);
}
}).listen(8124, '127.0.0.1');
答案 0 :(得分:0)
最后这是解决方案:
public boolean copyFiles(FileInputStream file, String fileName) {
boolean successful = false;
int cursor;
SmbFileOutputStream sfos;
SmbFile sFile;
String path;
NtlmPasswordAuthentication auth;
try{
String user = USER_NAME + ":" + PASSWORD;
System.out.println("User: " + user);
auth = new NtlmPasswordAuthentication(user);
StrictMode.ThreadPolicy tp = StrictMode.ThreadPolicy.LAX; StrictMode.setThreadPolicy(tp);
path = NETWORK_FOLDER + fileName+".jpeg";
System.out.println("Path: " +path);
sFile = new SmbFile(path, auth);
sfos = new SmbFileOutputStream(sFile);
long t0 = System.currentTimeMillis();
byte[] b = new byte[8192];
int n, tot = 0;
Log.d("asdf","initiating : total="+tot);
while((n = file.read(b))>0){
sfos.write( b, 0, n );
tot += n;
Log.d("asdf","writing : total="+tot);
}
successful = true;
Log.d("asdf","Successful : total="+tot);
}
catch (Exception e) {
successful = false;
e.printStackTrace();
Log.d("asdf","exxeption ");
}
return successful;
}