如何获取图像的这些值,尤其是拖动图像时从控制台显示的名称,大小,类型。并将这些数据显示给我的特定div
File {name: "free-windows-10-wallpaper_050549897_263.jpg", lastModified:
1464238729860, lastModifiedDate: Thu May 26 2016 12:58:49 GMT+0800 (Malay
Peninsula Standard Time), webkitRelativePath: "", size: 1185535…}
lastModified : 1464238729860
lastModifiedDate :Thu May 26 2016 12:58:49 GMT+0800 (Malay Peninsula Standard Time)
name : "free-windows-10-wallpaper_050549897_263.jpg"
size : 1185535
type : "image/jpeg"
webkitRelativePath : ""
__proto__ : File
这是js代码。
var obj = $('.drag_me');
obj.on('dragover', function(e){
e.stopPropagation();
e.preventDefault();
$(this).css('border', '2px solid #39ADCD');
});
obj.on('drop', function(e){
e.stopPropagation();
e.preventDefault();
$(this).css('border', '2px dotted #39ADCD');
var files = e.originalEvent.dataTransfer.files;
var file = files[0]; //<-- I need to get the size, name, image type of this image
console.log(file);
//upload(file);
});
所以我可以将这些数据显示给我的html
<div class="drag_here">
<div class="drag_me">
<center id="center_html">
Drag image here
</center>
</div>
</div>
答案 0 :(得分:1)
您可以使用
访问它file.name,
file.lastModified
注意:您需要在//upload(file)
声明之前加入它。
HTH