我有一个表单,用户可以使用uploadcare小部件上传文件。一旦上传,我可以输出/显示预览,但只有当文件类型是像jpg,png等图像时。但我需要能够显示其他文件类型,如PSD,PDF。我试图为此实现imagemagick,但混淆了如何将其与uploadcare一起使用,因为widget使用jquery来获取图像cdn。我在网上发现的大多数教程都是针对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')
);
});
});
答案 0 :(得分:0)
Uploadcare目前还不支持PSD和PDF预览功能。您必须使用允许您这样做的第三方服务。