我有一个包含多个图像的API响应。我正在使用get服务来获取表单上的文本和图像。文本即将到来,但我在从API检索图像时遇到困难。当前我在输出部分提供了价值但是没有显示图像。
我的图片API的键值是: - ***
result_data_for_editing.media.mediaPath
我想要检索图片的HTML是: -
<img type="file" id="files" multiple name="media" accept="image/*"/>
<output id="list" value="result_data_for_editing.media.mediaPath"></output>
和用于为该图像创建缩略图的相应javascript是: -
$(document).on('click', '.browse', function () {
var file = $(this).parent().parent().parent().find('.file');
file.trigger('click');
});
$(document).on('change', '.file', function () {
$(this).parent().find('.form-control').val($(this).val().replace(/C:\\fakepath\\/i, ''));
});
//function to create thumbanil of images uploaded on client-side
function handleFileSelect(evt) {
$("#list").html("");
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, validatedfiles, f; f = files[i], validatedfiles = files[i]; i++) {
var reader = new FileReader();
var imagearray = [];
imagearray = files[i];
// Closure to capture the file information.
reader.onload = (function (theFile) {
return function (e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<img class="thumbs_image" src="', e.target.result, '" title="', escape(theFile.name), '"/>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(imagearray);
// Read in the image file as a data URL.
reader.readAsDataURL(imagearray);
}
}
提前致谢