0

我有一个表单,用户可以使用 uploadcare 小部件上传文件。上传后,我可以输出/显示预览,但前提是文件类型是 jpg、png 等图像。但我还需要能够显示其他文件类型,如 PSD、PDF。我正在尝试为此实现imagemagick,但是由于小部件使用jquery来获取图像cdn,因此对如何将其与uploadcare一起使用感到困惑。而我在网上找到的大多数教程都是针对 php 的。

您可以查看此小提琴中的小部件片段:https ://jsfiddle.net/kamela101/e6ac6jb4/

$ = uploadcare.jQuery;
  // Create uploaded image list and append additional form fields to each item
  function installWidgetPreviewMultiple(widget, list) {
    widget.onChange(function(fileGroup) {
      list.empty();
      if (fileGroup) {
        $.when.apply(null, fileGroup.files()).done(function() {

          $.each(arguments, function(i, fileInfo) {
            // display file preview
            var $filename = fileInfo.name;// display file name
            var $fileurl = fileInfo.cdnUrl;// get file url
            var $src = fileInfo.cdnUrl + '-/resize/100x100/filename.jpg';// preview image source, resize to 100X100px and jpeg file type
            // append preview and name and form fields to each file uploaded inside thumb_list 
            list.append(
              $('<li class="thumb_list_item"><img src="' + $src+ '" alt="File Preview" class="preview-img">' + '<h4 class="filename">' + $filename + '</h4>' + '<div class="get-layer-wraper"><ul class="get-layer"><li class="layer-name"><label for="white-layer" class="layer-title">White Layer : </label></li><li><input id="white-layer" name="white-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="adhesive-layer" class="layer-title">Adhesive Layer : </label></li><li><input id="adhesive-layer" name="adhesive-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="block-layer" class="layer-title">Blocking Layer : </label></li><li><input id="block-layer" name="block-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul><div class="clear"><ul class="get-layer"><li class="layer-name"><label for="clear-layer" class="layer-title">Clear Layer : </label></li><li><input id="clear-layer" name="clear-layer[]" class="layer" type="number" value="0"></li><li>PX</li></ul></div></li>').appendTo(".thumb_list")
              );
          });
        });
      }
    });
  }
$(function() {
  $('.upload-area').each(function() {
    installWidgetPreviewMultiple(
      uploadcare.MultipleWidget($(this).children('input')),
      $(this).children('.thumb_list')
    );
  });
});
4

1 回答 1

0

Uploadcare 目前不支持 PSD 和 PDF 预览功能。您必须使用允许您执行此操作的第三方服务。

于 2016-10-10T15:45:55.713 回答