2017-12-24 7 views
1

私はjcifs-1.3.19.jarを追加したsmbアプリケーション内のNASサーバーに画像ファイルを送信するにはどうすればいいですか?

を使用してJavaでNAS serverに画像ファイル(JPG、PNG)を送りたいです。前述のように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; 
    } 
+0

はちょうど 'jpg'ファイルを送信すると、問題は何ですか? ファイルを読み込むために 'inputStream'クラスを使用し、' SmbFileOutputStream'を使用してNASにデータを送信することができます –

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

(like) あなたは 'パスがローカルパスの場合は「SmbFile」となります。 –

関連する問題