Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Jersey upload接收请求元而不是文件_Angularjs_File Upload_Glassfish_Jersey - Fatal编程技术网

Angularjs Jersey upload接收请求元而不是文件

Angularjs Jersey upload接收请求元而不是文件,angularjs,file-upload,glassfish,jersey,Angularjs,File Upload,Glassfish,Jersey,我已经让这段代码运行良好,但是现在,几次修订之后,当我回到它的上传功能时,它似乎只读取请求的元数据,而不是实际的文件。例如,这就是我在尝试上载txt文件时得到的结果: ------WebKitFormBoundaryF5IARVFZQSY3ZPJ4内容配置:表单数据;name=“file”未定义----WebKitFormBoundaryF5IARVFzqsY3zpj4-- JS: $scope.setFiles = function(element) { $scope.$apply(f

我已经让这段代码运行良好,但是现在,几次修订之后,当我回到它的上传功能时,它似乎只读取请求的元数据,而不是实际的文件。例如,这就是我在尝试上载txt文件时得到的结果:

------WebKitFormBoundaryF5IARVFZQSY3ZPJ4内容配置:表单数据;name=“file”未定义----WebKitFormBoundaryF5IARVFzqsY3zpj4--

JS:

$scope.setFiles = function(element) {
    $scope.$apply(function($scope) {
        console.log('files:', element.files[0]);
        // Turn the FileList object into an Array
        $scope.files = element.files[0];
        $scope.progressVisible = false;
    });
};

$scope.analyseFile = function() {
    var fd = new FormData();
    fd.append("file", $scope.files[0]);

    var xhr = new XMLHttpRequest();
    xhr.addEventListener("load", uploadComplete, false);
    xhr.addEventListener("error", uploadFailed, false);
    xhr.addEventListener("abort", uploadCanceled, false);
    xhr.open("POST", "/rest/analysisController/analyseFile");
    $scope.progressVisible = false;
    xhr.send(fd);
};
以及服务器端:

@POST
@Path("analyseFile")
@Produces("application/json; charset=UTF-8")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response analyseFile(
        @FormDataParam("file") InputStream uploadedInputStream) throws
        RemoteException {

    System.out.println(getStringFromInputStream(
            uploadedInputStream));

    return Response.ok().build();
}
我还包括多部分依赖项:

<dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <version>2.5.1</version>
        <scope>provided</scope>
    </dependency>

org.glassfish.jersey.media
泽西岛媒体多部分
2.5.1
假如

所以我的问题是切换到“angular file upload.js”的缩小版本。由于某种原因,缩小的版本不起作用,因此它实际上没有发送文件的内容

我不确定这个答案是否真的能帮助任何人,但以防万一