Цель — отправить файл на сервер Java через запрос на публикацию angularjs.
Код Angular JS :
Код: Выделить всё
var imgMetadata = {author: "a",title: "a",description: "a.",keywords: "a"};
console.log("imgMetadata"+imgMetadata);
var fd = new FormData();
fd.append('fileMetadata', JSON.stringify(imgMetadata));
fd.append('file', upoadFileField\[0\].files\[0\]);
console.log("Call http");
var REST_BASE_URL = PluginHelper.getPluginRestUrl("apponboarding");
var uploadurl = REST_BASE_URL+ "/iiq/uploadfile";
console.log("File upload url is "+uploadurl);
$http.post(uploadurl, fd, {transformRequest: angular.identity,headers: {"X-XSRF-TOKEN": PluginHelper.getCsrfToken(),"Content-Type": undefined}}).then(function successCallback(response)
{
console.log("In success callback");
var status = response.status;if(status == "200")
{
var isValid = response.data;
console.log("FIleupload function in java "+isValid);
if(isValid == "filecopied"){
$scope.errorText = "filecopied :";
}
else
{
$scope.errorText = "Issue in copying";
}
}
}, function errorCallback(response) { console.log("In error callback"); $scope.errorText = "Error in callback file function"; });
Код: Выделить всё
Java CodeКод: Выделить всё
@POST@Path("/iiq/uploadfile")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@RequestParam("file") MultipartFile file) {
try{
log.error("file received.");
return Response.status(Response.Status.OK).entity("filecopied").build();
}
catch (Exception e){
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Cannot copy!!").build();
}
}
Если я удалю все аргументы в публичном ответе uploadFile()
, тогда моя функция вызывается и строка печатается.
Подробнее об ошибке:
2024-10-21T12:03: 08,357 ОШИБКА http-nio-8080-exec-7ailpoint.web.SailPointContextRequestFilter:74 - java.lang.IllegalStateException: область запроса уже закрыта.
javax.servlet.ServletException: java.lang.IllegalStateException: Request область действия уже закрыта.
Подробнее здесь: https://stackoverflow.com/questions/791 ... anugularjs
Мобильная версия