测试时出现Rails Active_storage ActiveStorage :: IntegrityError

时间:2018-11-12 09:33:26

标签: ruby-on-rails rails-activestorage

在rails 5.2上,我将画布另存为blob,然后通过Active storage将其发送到Azur存储。

在我的机器上,借助开发环境,可以完美创建png并将其完美发送到Azur Blob,然后将其附加到模型上。

但是在将机器上的Blob连接到映像时,在测试计算机(具有测试环境)上,我收到ActiveStorage :: IntegrityError。

发送png的javascript

            var project_id = 2;
            var csrf_token  = $("meta[name=csrf-token]").attr("content");
            var project_metadata = new FormData();
            project_metadata.append("utf8","✓");
            project_metadata.append("authenticity_token",csrf_token);
            project_metadata.append("projet_id",project_id.toString());
            project_metadata.append("commit","Create Projet");
            var file_name = "rdc.png";
            var upload_file_field = that.drawing.getElement().toBlob(function(blob) {
                var file = new File([blob], file_name, {type: "image/png", lastModified: Date.now()});
                var url = "/projects/"+project_id.toString()+"/store_plan"
                project_metadata.append("images",file,file_name);   
                $.ajax({
                  type: "POST",
                  url: url,
                  data: project_metadata,
                processData: false,
                contentType: false,                   
                  success: function(){
                    console.log("images save");
                  }
                });
            })

控制器

def store_plan
  @project.images.attach(io: params["images"].to_io, filename: params["images"].original_filename)
end

storage.yml

azure_dev:
   service: AzureStorage
   storage_account_name: "XXXXX"
   storage_access_key: "..."
   container: projectsdevelopment

test:
   service: AzureStorage
   storage_account_name: "XXXXX"
   storage_access_key: "..."
   container: projectstest

我的开发机是Mac book pro,我的测试机是Ubuntu。

不明白为什么我会在测试中收到ActiveStorage :: IntegrityError,开发时一切正常吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

解决方案

我最终使用fetch代替了$.ajax({}),这在两方面都有效。