ruby-on-rails – Rails上传到AWS创建.zip.cpgz文件循环

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails上传到AWS创建.zip.cpgz文件循环前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我遇到一个奇怪的情况,一些文件,特别是ZIP格式,当我的Rails应用程序上传到AWS时,它们被损坏/转换.当下载和解压缩时,他们变成一个CPGZ格式,它解压缩成一个ZIP,无限地这样做.

我没有注意到导致这种情况的模式,所以看起来似乎是零星的,并且可以在上传之前确认文件没有被破坏.我发现的唯一其他issue/topicPHP有关,似乎是不同的情况.

我使用AWS SDK for Ruby v1(不是v2,因为我的Rails版本)和jQuery-File-Upload.由于一些文件很大,我正在使用分块上传.

在我的控制器中,预先编写的POST URL是这样创建的:

S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}-${filename}",success_action_status: '201')

并且jQuery文件上传是这样设置的(为简洁起见,删除了一些部分):

this.$el.fileupload({
  fileInput: this.uploadField,// this is an <input type="file">
  url: this.awsURL,// https://BUCKET.s3.amazonaws.com/
  formData: JSON.parse(this.awsData),// {"AWSAccessKeyId":"...","key":"uploads/1234-${filename}","policy":"...","signature":"...","success_action_status":"201"}
  type: 'POST',autoUpload: true,paramName: 'file',dataType: 'XML',replaceFileInput: false,maxChunkSize: 1000000,add: function(event,data) {
    var file = data.files[0];
    var fileType = file.type;

    // Check file type
    if (~'ai sketch psd jpg jpeg png zip ttf woff eot gif'.indexOf(fileType.toLowerCase())) {
      return alert('Sorry,that file type is not supported');
    };

    data.submit();
  },progress: function(event,data) {
    // Display progress
  },done: function(event,data) {
    var file = data.files[0];
    var fileName = file.name.replace(/ /g,"_");
    var item = _this.uploadedItems[fileName];
    var key = $(data.jqXHR.responseXML).find("Key").text();
    // awsHost = BUCKET.s3.amazonaws.com
    var url = '//' + _this.awsHost + '/' + key;

    // Set form values using above info
  },fail: function(event,data) {
    // Alert failure
  }
});

有没有人经历过这个?这很令人沮丧.

解决方法

发送请求时,将内容类型设置为application / zip.

SEE https://github.com/aws/aws-sdk-ruby/blob/aws-sdk-v1/lib/aws/s3/presigned_post.rb

原文链接:https://www.f2er.com/ruby/272035.html

猜你在找的Ruby相关文章