Firefox上的ng-file-upload中断

时间:2016-04-09 18:34:17

标签: javascript angularjs

我在AngularJS应用中使用ng-file-upload,它在Chrome和Safari中工作正常但在Firefox中断了,我得到了一个

中的Error: Argument 2 of FormData.append does not implement interface Blob.消息

还有其他人有这个问题吗?

包含指令的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>

以及向服务器发出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);
    });
  }
}

1 个答案:

答案 0 :(得分:0)

因此我的问题的解决方案基于this comment on Github来更改

file: formData.filesAttachments

file: new Blob([formData.filesAttachments])