[英]Can we create a customized URL for the file which is selected from the input type="file" which points to file and downloads the file wherever used?
<input type="file" id="ota" name="ota" accept=".bin" />
<div id="btn-container">
<button id="update-button" >Update</button>
</div>
在这里,当从输入类型=“文件”中选择文件时,我想创建一个类似的 URL(http://<server_host_ip>:<server_port>/<image_name.bin>)
你是这个意思?
document.getElementById("ota").addEventListener("change", function() { const file = this.files[0]; const fileName = file.name; console.log(fileName) const link = document.getElementById("dl") link.href = location.origin + "/" + fileName link.removeAttribute("hidden") })
<input type="file" id="ota" name="ota" accept=".bin" /> <button id="update-button">Update</button> <a href="" download id="dl" hidden>download</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.