JQuery文件上传(RailsCasts#383):将多个分辨率上传到S3

时间:2015-11-17 10:02:47

标签: jquery-file-upload railscasts

我使用RailsCasts第383集中描述的upload_helper直接将文件上传到AWS S3。

以下适用于我,图像重新调整为800x600并存储到S3。

jQuery ->
  $('#fileupload').fileupload
    processQueue: [
      {
        action: 'loadImage'
        fileTypes: /^image\/(gif|jpeg|png)$/
        maxFileSize: 20000000
      }
      {
        action: 'resizeImage'
        maxWidth: 800
        maxHeight: 600
      }
      { action: 'saveImage' }
    ]
   add: (e, data) ->
    $.blueimp.fileupload.prototype.options.add.call(this, e, data)

现在,我想要做的还是将缩小版本存储得更小。我有以下代码,它似乎与它尝试使用相同的POST请求将两个文件上传到S3的事实不同。

$.blueimp.fileupload::processActions.duplicateImage = (data, options) ->
  if data.canvas
    data.files.push data.files[data.index]
  data

jQuery ->
  $('#fileupload').fileupload
    processQueue: [
      {
        action: 'loadImage'
        fileTypes: /^image\/(gif|jpeg|png)$/
        maxFileSize: 20000000
      }
      {
        action: 'resizeImage'
        maxWidth: 800
        maxHeight: 600
      }
      { action: 'saveImage' }
      { action: 'duplicateImage' }
      {
          action: 'resizeImage'
          maxWidth: 400
          maxHeight: 300
      }
      {action: 'saveImage'}
    ]
    add: (e, data) ->
      $.blueimp.fileupload.prototype.options.add.call(this, e, data);

我得到的错误如下。

POST https://mybucket-uploads.s3.amazonaws.com/ 400(错误请求)

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidArgument</Code><Message>POST requires exactly one file upload per request.</Message><ArgumentName>file</ArgumentName><ArgumentValue>2</ArgumentValue><RequestId>F2D33882A6556810</RequestId><HostId>3DP7aHL4aR1ErG5eIWh2kgQUXbsrytBU2u/pdQO746X2njjWckUVZtivcIJoY9qYsOBN13TPbyU=</HostId></Error>

我怎样才能让它发挥作用?

0 个答案:

没有答案