2017-08-29 8 views
0

2日間まだ解決策が見つかりませんでしたので、これを行っています eclipseワークスペースのイメージフォルダにイメージをアップロードしています。イメージが初めてアップロードされたときに問題が発生し、画像は、ワークスペース内のフォルダと、空のキャッシュリロードその後それが正常に動作しイメージはフロントエンドに反映されていません

これは私のhtml

</div><img ng-src="{{image}}" alt="image caption" ngf-src="imagePath" style="height: 150px;width: 150px;margin: 10px;" ng-show="imagevisible"></div> 

であり、これは私のコントローラである

$scope.uploadFiles = function(file) { 
    debugger; 
    $scope.fileObj = file; 

    $scope.fileName = $scope.fileObj.name; 
    console.log($scope.fileObj.name); 
    } 
$scope.submit=function(){ 
Upload.upload({ 
     //method : 'POST', 
      url  : '/WarehouseMgmt/material/add_mtr', 
      data : { 
         model : $scope.NewMtr, 
         file : $scope.fileObj 
        }, 
     // headers : {'Content-Type': 'application/json; charset=utf-8'} 

     }).then(function(response){ 
      debugger;  
      //$mdDialog.cancel(); 

      $scope.showAddMtrlToast(); 
      $window.location.href="#!/Material/" 
      $route.reload(); 
     },function(response){ 
       debugger; 
       console.log(response.status);    
       if(response.status==500){ 
        $scope.showMtrlExistToast(); 
       } 
      }); 
    }; 
} 

と私のJavaのコントローラメソッドのアップロードイメージ

public String uploadMaterialImage(MultipartFile fileObj) { 
    Properties properties = new Properties(); 
    String filename = "views.properties"; 
    InputStream input = getClass().getClassLoader().getResourceAsStream(filename); 

    if (input == null) { 
     System.out.println("Sorry, unable to find " + filename); 
     return ""; 
    } 

    try { 
     properties.load(input); 
     pathSave = properties.getProperty("saveImagePath"); 
    } catch (IOException e1) { 
     e1.printStackTrace(); 
    } 

    String filePath="";  
    if(!fileObj.isEmpty()) 
    { 
    try { 
     System.out.println("inside this serviceImoplMethod!"); 
     byte[] bytes = fileObj.getBytes(); 
     String rootPath = System.getProperty("catalina.home");  
    File dir = new File(pathToSave); 
     File dir = new File(pathSave); 
     if (!dir.exists()) 
      dir.mkdirs(); 

     File serverFile = new File(dir.getAbsolutePath() 
       + File.separator +fileObj.getOriginalFilename()); 
     BufferedOutputStream stream = new BufferedOutputStream(
       new FileOutputStream(serverFile)); 
     stream.write(bytes); 
     stream.close(); 

     filePath=serverFile.getAbsolutePath(); 
     System.out.println("sysout file parh::" + filePath); 

    } catch (Exception e) { 
     //return "You failed to upload " + name + " => " + e.getMessage(); 
    } 
    return filePath; 
    } 
return ""; 
} 

助けてください!

答えて

0

私は、バックエンドとしてjava eeを使用し、それをwar/jarファイルとしてデプロイし、アップロードしたイメージをプロジェクトフォルダに保存すると、プロジェクトを再デプロイする必要があると思います。デプロイされたJavaプロジェクトは、ファイルの1つが変更されたときに再デプロイしないためです。 アップロードされた画像をあなたのプロジェクトではない別のフォルダに保存してみてください。

+0

あなたのsuggetionをありがとう、私はそれを試しましたが、うまくいかなかった –

関連する問題