gpt4 book ai didi

java - 如何在我的应用程序中将图像文件发送到 NAS 服务器?

转载 作者:太空宇宙 更新时间:2023-11-04 10:50:03 31 4
gpt4 key购买 nike

我想发送图片文件(jpg、png)到NAS server在java中使用smb

我添加了 jcifs-1.3.19.jar 。如前所述herehere

编辑:我已经使用此代码成功将jpeg图像发送到服务器上的共享文件夹,但速度非常慢,发送几乎1kb/秒。有什么解决办法吗??

    static final String USER_NAME = "Waqas";
static final String PASSWORD = "mypass";
static final String NETWORK_FOLDER = "smb://DESKTOP-LAP/Users/Waqas/";

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;
auth = new NtlmPasswordAuthentication(user);
StrictMode.ThreadPolicy tp = StrictMode.ThreadPolicy.LAX; StrictMode.setThreadPolicy(tp);
path = NETWORK_FOLDER + fileName;
sFile = new SmbFile(path, auth);
sfos = new SmbFileOutputStream(sFile);

while((cursor = file.read())!=-1){
sfos.write(cursor);
}
successful = true;
System.out.println("Successful " + successful);
}

catch (Exception e) {
successful = false;
e.printStackTrace();
}
return successful;
}

最佳答案

最后是解决方案:

  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;
}

关于java - 如何在我的应用程序中将图像文件发送到 NAS 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47961360/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com