簡體   English   中英

如何獲取上傳圖片的圖片名稱和大小

[英]How to get image name and size for the uploaded image

我正在使用代碼來解決我的問題。 通過使用下面的代碼,我試圖獲取圖像名稱及其以字節/Mbps 為單位的大小。

 'use strict'; const myImages = []; function addImage(imageBlob) { myImages.push(imageBlob); } function redrawImages() { const divForImages = document.getElementById('myImages'); divForImages.innerHTML = ''; myImages.forEach((imageBlob) => { const img = document.createElement('img'); img.src = URL.createObjectURL(imageBlob); divForImages.appendChild(img); }); } function addImageAndRedraw() { const fileInput = document.getElementById('fileInput'); if (fileInput.files.length === 1) { addImage(fileInput.files[0]); redrawImages(); } else { alert('No file selected. Select a file and try again.'); } } const button = document.getElementById('button'); button.addEventListener('click', addImageAndRedraw);
 <.DOCTYPE html> <html> <head> </head> <body> <h1>My images</h1> <input id="fileInput" type="file" accept="image/*" multiple="false" value="Select image"> <input id="button" type="button" value="Add image and redraw"> <hr> <div id="myImages"></div> <script src="album.js"></script> </body> </html>

我曾嘗試使用img.name但已棄用。

怎么做? 任何幫助將不勝感激

imageBlob不是一個 blob。 它是一個File ,它有一個name屬性。 該名稱不會轉移到img DOMElement。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM