HTML 업로드 양식과이를 제어하는 각도 조절기가 있습니다. 컨트롤러에서 파일을 업로드하는 방법을 알았지 만,이 파일을 서버로 이동/업로드 할 수있는 방법은 무엇입니까? 나는 멀터를 체크 아웃했는데 클라이언트 측에서 요구할 수 없기 때문에 이것이 나의 경우에는 작동 할 것이라고 생각하지 않는다.클라이언트 측에서 서버로 파일을 옮깁니다.
다음app.controller('uploadCtrl', function($scope, $location, $http){
$scope.enableSubmitButton = false;
$scope.fileSizeError = false;
var selectedFiles = [];
//get files selected
$scope.getFiles = function($files){
selectedFiles = $files;
//display upload button if there is a valid file to upload
if(selectedFiles.length !== 0){
$scope.enableSubmitButton = true;
}
}
$scope.upload = function(){
if($scope.enableSubmitButton){
//disable to prevent clicking again
$scope.enableSubmitButton = false;
//correctly shows the file data
console.dir(selectedFiles);
//upload files to server
//What should I do here?
}
}
});
에 대한 파일 객체와 URL을 통과은 각 – bitten
selectedFiles에서'$ http' 서비스 파일의 배열입니다. 나는 $ http 서비스를 보았지만 파일로 게시물 요청을하는 방법을 알아낼 수 없었다. – ninesalt
http 서비스는 (파일을 올리면서) 사용하고자하는'post' 메소드를 가지고 있습니다. 콜백이 필요한 경우 post 함수를'success' 또는'then'과 연결할 수 있습니다. 아마도 [이 질문과 답변] (http://stackoverflow.com/questions/15894650/http-post-in-angular-js) 도움이 될까요? – bitten