Javascript Dropzone.js显示存储的图像
我在我的Laravel应用程序中使用dropzone.js在我的平台上上传和显示图像。储存很好。我正在将它们保存到数据库和本地文件夹结构中,该结构具有完整图像的完整文件夹大小和图标大小,这些图像应该适合作为缩略图,基本上是图像的较小副本 我面临的问题是当我尝试显示图像时。这是我的dropzone配置文件:Javascript Dropzone.js显示存储的图像,javascript,php,laravel,dropzone.js,Javascript,Php,Laravel,Dropzone.js,我在我的Laravel应用程序中使用dropzone.js在我的平台上上传和显示图像。储存很好。我正在将它们保存到数据库和本地文件夹结构中,该结构具有完整图像的完整文件夹大小和图标大小,这些图像应该适合作为缩略图,基本上是图像的较小副本 我面临的问题是当我尝试显示图像时。这是我的dropzone配置文件: Dropzone.options.realDropzone = { previewsContainer: '#dropzonePreview', previewTemplate: do
Dropzone.options.realDropzone = {
previewsContainer: '#dropzonePreview',
previewTemplate: document.querySelector('#preview-template').innerHTML,
addRemoveLinks: true,
dictRemoveFile: 'Remove',
// The setting up of the dropzone
init: function () {
var myDropzone = this
$.get('/image', function (data) {
$.each(data.images, function (key, value) {
var file = {name: value.original, size: value.size}
myDropzone.options.addedfile.call(myDropzone, file)
myDropzone.options.thumbnail.call(myDropzone, file, 'images/icon_size/' + value.server)
myDropzone.emit('complete', file)
})
})
this.on('removedfile', function (file) {
$.ajax({
type: 'POST',
url: 'image/destroy',
data: {id: file.name, _token: $('#csrf-token').val()},
dataType: 'html',
success: function (data) {
var rep = JSON.parse(data)
}
})
})
},
error: function (file, response) {
if ($.type(response) === 'string')
var message = response //dropzone sends it's own error messages in string
else
var message = response.message
file.previewElement.classList.add('dz-error')
_ref = file.previewElement.querySelectorAll('[data-dz-errormessage]')
_results = []
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i]
_results.push(node.textContent = message)
}
return _results
},
success: function (file, done) {
}
}
Ajax调用/image可以正常工作,并返回数据库中的图像实例
但是当每个图像都应该包含在视图中时,它就出错了
我面临的问题是,它出错了,因为我在一个项目路径下,因为这些是连接到一个项目的图像。我不知道如何删除该部分路由,以便直接从我的公用文件夹获取图片如果有人遇到相同的问题,我已通过明确定义用于获取的URL来解决此问题:
myDropzone.options.thumbnail.call(myDropzone, file, "http://" + window.location.hostname + '/images/icon_size/' + value.server)
http://部分是必需的,否则它只是将其附加到现有链接