0

我的页面上每个上传的缩略图旁边都有一个编辑按钮,单击该按钮会调用 Aviary 模式。当我在 Aviary 中保存编辑结果时,我想做的是替换 FP 上的原始文件。filepicker.saveAs 似乎不是正确的解决方案,因为我不想保存到新文件,我只想替换 FP 上的文件。“Saving Back”文档似乎不适用,因为它说要将完整文件发布到原始 URL。理想情况下,我只想有一个函数获取原始 URL 和新的 Aviary URL,并替换原始 URL 的内容。

目前这可能吗?谢谢!!!

我在这里粘贴了我的代码:

<script src='http://feather.aviary.com/js/feather.js'></script>
<script src="https://api.filepicker.io/v0/filepicker.js"></script>
<script type="text/javascript">
$(document).on('click', '.delete-image', function(e) {
  var image = $(this).closest('tr').attr('data-image');
  $('.modal-footer .btn-danger').remove();
  $('.modal-footer').append("<button class='delete-confirmed btn btn-danger' data-image='"+image+"'>Delete</button>");
  $('#myModal').modal('show');
  return false;
});

$(document).on('click', '.delete-confirmed', function(e) {
  e.preventDefault();
  var image = $(this).attr('data-image');
  var row = $("tr[data-image="+image+"]");
  $('#myModal').modal('hide');
  $.ajax({
    url: row.attr('data-link'),
    dataType: 'json',
    type: 'DELETE',
    success: function(data) {
      if (data.success) {
        row.hide();
        filepicker.revokeFile(row.attr('data-fplink'), function(success, message) {
          console.log(message);
        });
      }
    }
  });
  return false;
});

//Setup Aviary
var featherEditor = new Aviary.Feather({
    //Get an api key for Aviary at http://www.aviary.com/web-key
    apiKey: '<%= AVIARY_KEY %>',
    apiVersion: 2,
    appendTo: ''
});
//When the user clicks the button, import a file using Filepicker.io
$(document).on('click', '.edit-image', function(e) {
  var image = $(this).closest('tr').attr('data-image');
  var url = $(this).closest('tr').attr('data-fplink');
  $('#aviary').append("<img id='img-"+image+"'src='"+url+"'>");
  //Launching the Aviary Editor
  featherEditor.launch({
    image: 'img-'+image,
    url: url,
    onSave: function(imageID, newURL) {
      //Export the photo to the cloud using Filepicker.io!
      //filepicker.saveAs(newURL, 'image/png');
      console.log('savin it!');
    }
  });
});

filepicker.setKey('<%= FILEPICKER_KEY %>');
var conversions = { 'original': {},
                    'thumb': {
                    'w': 32,
                    'format': 'jpg'
                  },
};
$(document).on("click", "#upload-button", function() {
  filepicker.getFile(['image/*'], { 'multiple': true,
                                    'services': [filepicker.SERVICES.COMPUTER, filepicker.SERVICES.URL, filepicker.SERVICES.FLICKR, filepicker.SERVICES.DROPBOX, filepicker.SERVICES.IMAGE_SEARCH],
                                    'maxsize': 10000*1024,
                                    'conversions': conversions
                                  },
                                  function(images){
      $.each(images, function(i, image) {
        $.ajax({
          url: "<%= product_images_path(@product.id) %>",
          type: 'POST',
          data: {image: JSON.stringify(image)},
          dataType: 'json',
          success: function(data) {
            if (data.success) {
              $('.files').append('<tr><td><img src="'+image.data.conversions.thumb.url+'"</td></tr>')
            }
          }
        });
      });
  });
});

4

1 回答 1

0

您实际上也可以将 url 发布到文件选择器 url,例如

curl -X POST -d "url=https://www.filepicker.io/static/img/watermark.png"
    https://www.filepicker.io/api/file/gNw4qZUbRaKIhpy-f-b9

或在javascript中

$.post(fpurl, {url: aviary_url}, function(response){console.log(response);});
于 2012-09-28T19:10:02.673 回答