Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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 更改ng文件上载的内容类型_Angularjs_Ng File Upload - Fatal编程技术网

Angularjs 更改ng文件上载的内容类型

Angularjs 更改ng文件上载的内容类型,angularjs,ng-file-upload,Angularjs,Ng File Upload,我正在尝试使用ng文件上载上载文件。大部分情况下,我都能做到这一点,但调用的API中存在一个bug,这意味着.xlsx文件无法正确上传。其他文件类型也可以。我被告知,强制负载中的内容类型为“application/x-zip-compressed”可以上传文件。不幸的是,我不知道如何改变这一点。有效载荷如下所示: ------WebKitFormBoundary9rVv6WxE2BM7vFxz Content-Disposition: form-data; name="file[0]"; fil

我正在尝试使用ng文件上载上载文件。大部分情况下,我都能做到这一点,但调用的API中存在一个bug,这意味着.xlsx文件无法正确上传。其他文件类型也可以。我被告知,强制负载中的内容类型为“application/x-zip-compressed”可以上传文件。不幸的是,我不知道如何改变这一点。有效载荷如下所示:

------WebKitFormBoundary9rVv6WxE2BM7vFxz
Content-Disposition: form-data; name="file[0]"; filename="My Excel File.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet


------WebKitFormBoundary9rVv6WxE2BM7vFxz--
------WebKitFormBoundary9rVv6WxE2BM7vFxz
Content-Disposition: form-data; name="file[0]"; filename="My Excel File.xlsx"
Content-Type: application/x-zip-compressed


------WebKitFormBoundary9rVv6WxE2BM7vFxz--
if (file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
  file = file.slice(0, file.size, "application/x-zip-compressed")
}
Upload.upload({..., data: {file: file}, ...})
但需要像这样:

------WebKitFormBoundary9rVv6WxE2BM7vFxz
Content-Disposition: form-data; name="file[0]"; filename="My Excel File.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet


------WebKitFormBoundary9rVv6WxE2BM7vFxz--
------WebKitFormBoundary9rVv6WxE2BM7vFxz
Content-Disposition: form-data; name="file[0]"; filename="My Excel File.xlsx"
Content-Type: application/x-zip-compressed


------WebKitFormBoundary9rVv6WxE2BM7vFxz--
if (file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
  file = file.slice(0, file.size, "application/x-zip-compressed")
}
Upload.upload({..., data: {file: file}, ...})
有人能帮我改变一下吗?我已尝试更改文件对象的type属性,但没有进行更改

上传的功能是

$scope.uploadThenRun = function (file) {
    Upload.upload({
        url: 'https://'+ ppService.ppServer+ ':'+ ppService.sslPort + '/jobs/',
        data: {file: file}
    }).then(function (resp) {
        var jobID = resp.data.data.value;
        $scope.loadParentFormulation(jobID);        
    }, function (resp) {
    }, function (evt) {
    });
从一个div调用,如下所示:

<div class="my-drop-zone">
      <div ngf-drop="uploadThenRun($files)" class="drop-box well"
       ngf-drag-over-class="'dragover'" ngf-multiple="true">Drop your file here</div>
</div>

把你的文件放在这里
这是发送的网络请求。需要更改的是负载中的内容类型


希望有人能帮忙

您可以使用标题定义内容类型

$scope.uploadThenRun = function (file) {
    Upload.upload({
        url: 'https://'+ ppService.ppServer+ ':'+ ppService.sslPort + '/jobs/',
        data: {file: file},
        headers : {'Content-Type': 'application/x-zip-compressed'}
    }).then(function (resp) {
        var jobID = resp.data.data.value;
        $scope.loadParentFormulation(jobID);        
    }, function (resp) {
    }, function (evt) {
    });

您可以在上传之前更改文件类型,如下所示:

------WebKitFormBoundary9rVv6WxE2BM7vFxz
Content-Disposition: form-data; name="file[0]"; filename="My Excel File.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet


------WebKitFormBoundary9rVv6WxE2BM7vFxz--
------WebKitFormBoundary9rVv6WxE2BM7vFxz
Content-Disposition: form-data; name="file[0]"; filename="My Excel File.xlsx"
Content-Type: application/x-zip-compressed


------WebKitFormBoundary9rVv6WxE2BM7vFxz--
if (file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
  file = file.slice(0, file.size, "application/x-zip-compressed")
}
Upload.upload({..., data: {file: file}, ...})

这将使新类型的文件具有相同的内容。

为此使用多部分表单数据。请求已使用多部分表单数据。我需要更改的是有效负载的内容类型。我已经在上面的帖子中添加了一个截屏,希望能够澄清。谢谢你的回复!我已经试过了,这个headers选项会更改请求的头,我需要更改的是负载上的内容类型。这不适用于ngx uploader,有没有办法使用ngx uploader插件?