简体   繁体   English

ng-file-upload在Firefox上中断

[英]ng-file-upload breaks on Firefox

I'm using ng-file-upload in an AngularJS app, it works fine in Chrome and Safari but it breaks in Firefox, I get an Error: Argument 2 of FormData.append does not implement interface Blob. 我在AngularJS应用程序中使用ng-file-upload,在Chrome和Safari中工作正常,但在Firefox中坏了,我得到一个Error: Argument 2 of FormData.append does not implement interface Blob. message in the console. 控制台中的消息。

Has anyone else had this problem? 有没有其他人有这个问题?

The html snippet that contains the directive: 包含指令的html代码段:

<label class="article-field-label" for="article_description">Imagens</label>  
  <div class="file-upload-container">
    <a class="btn btn-default cancel-file-upload-button" ng-click="cancelPic(1)"><span>&times;</span></a>
    <div class="button thumbnail-placeholder" ngf-select ng-file-select="onFileSelect($files)"
                  ng-model="article.filesAttachments.file1" name="file" type="file"
                  ngf-pattern="'image/*'" ngf-accept="'image/*'" ngf-max-size="5MB" ngf-min-height="100"
                  ngf-resize="{width: 100, height: 100}">
    <img ngf-src="thumbnailImage(1)">
  </div>
</div>

and my service that makes the POST request to the server: 以及向服务器发出POST请求的服务:

sendPayload = function(formData, method, url) {
  var options;
  options = {
    url: url,
    method: method,
    file: formData.filesAttachments,
    headers: { 'Content-Type': 'application/json' },
    fields: {
      article: {
        title: formData.title, 
        price: formData.price,
        user_id: formData.user_id,
        category: formData.category,
        article_state: formData.article_state,
        description: formData.description,
        city: formData.city,
        article_id: formData.article_id
      }
    }
  };
  if(method=='POST'){
    return Upload.upload(options).success(function(data, status){
      if(status === 201) {
        var file = formData.filesAttachments
        angular.forEach(file, function(file){
          file.upload = Upload.upload({
            url: '/articles/' + data.article_id + '/attachments.json',
            file: file,
            headers: { 'Content-Type': 'application/json' },
            method: 'POST'
          })
        })
      }
    }).success(function(data, status){
      latestArticleCreatedID = data.article_id;
    }).error(function(data, status) {
      console.log("Failed" + status);
    });
  }
}

So the solution for my problem was based on this comment on Github to change the 因此,针对我的问题的解决方案基于对Github的评论,以更改

file: formData.filesAttachments

to

file: new Blob([formData.filesAttachments])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM