2 回答

TA貢獻1871條經驗 獲得超13個贊
您可以使用 Vanilla JS URL.createObjectURL 來完成此操作。只需使用表單添加視頻,然后使用視頻標簽中的 URL。
<body>
? ? Add a video here:
? ? <br>
? ? <input type="file" id="video-url-example">
? ? <br>
? ? ..and it will playback here, without any upload:
? ? <br>
? ? <div id="video-container" style="width: 50%"></div>
? ? <script>
? ? ? const input = document.querySelector('#video-url-example');
? ? ??
? ? ? input.addEventListener('change', () => {
? ? ? ? const file = input.files[0];
? ? ? ? const url = URL.createObjectURL(file);
? ? ? ? document.querySelector('#video-container').innerHTML = `
? ? ? ? ? <video autoplay loop width="500" src="${url}" />
? ? ? ? `;
? ? ? });
? ? </script>
? ??
? ?
</body>

TA貢獻1859條經驗 獲得超6個贊
我知道出于安全原因 Javascript 替代了 fakepath
是的。您無法使用文件輸入從本地磁盤中選取文件以供 Web 服務器使用。即使服務器在同一臺計算機上運行也不會。
是否有可能使用 Node/Express 獲得真實路徑,如果可以,如何最好地實現?
使用fs
模塊讀取文件系統并將該數據從服務器發送到瀏覽器。
您可能還想查看 Electron.js,它是為使用 Node.js 和嵌入式瀏覽器構建桌面應用程序而設計的。它使用允許您讀取文件路徑的 API 擴展了瀏覽器。
添加回答
舉報