英文:
Chrome Extension download empty MP3 file
问题
以下是您要翻译的内容:
"所以,就像标题所说,我想强制Chrome扩展下载一个空的MP3文件。尽管我成功地提示了下载,但每次我下载这个“空”文件时,都会出现“失败 - 网络错误”的错误。这是处理下载的函数:
function download(title) {
return new Promise(resolve => chrome.downloads.download({url: "data:application/mp3", filename: `${title}.mp3`, saveAs: true}, resolve))
}
我假设数据中没有足够的比特(或所需的比特)使其被分类为MP3文件。不幸的是,我不知道MP3文件应该是什么样子的,所以我无法自己修复它。我的问题是,如何能够下载空的MP3对象,而不让Chrome说它因“网络错误”而失败?
如果有人能帮助我,那将是太棒了。如果你想知道,我下载空的MP3文件是为了将其用作位置蓝图。下载后,路径将被发送到外部应用程序,然后该应用程序将用实际的MP3文件覆盖该文件。如果您有任何问题,请告诉我。感谢您的时间和帮助,真的非常感激。"
英文:
So, just like the title says, I want to force a Chrome extension to download an empty MP3 file. Although I did manage to actually prompt a download, every time I download the "empty" file, I get a "Failed - Network error" error. Here is the function that handles the download:
function download(title) {
return new Promise(resolve => chrome.downloads.download({url: "data:application/mp3", filename: `${title}.mp3`, saveAs: true}, resolve))
}
My assumption is that there aren't enough bits (or the required ones) in the data of the MP3 for it to even be classified as an mp3 file. I unfortunately have no idea how MP3 files are supposed to look like, so I sadly cannot fix it on my own. My question to you is, how would I be able to download the empty MP3 object without Chrome saying that it failed due to a "network error"?
If anyone could help me, that would be amazing. If you are wondering, the reason I am downloading an empty MP3 file is for it to be used as a location blueprint. After it is downloaded, the path will be sent to an external application which will then overwrite the file with the actual MP3. If you have any questions, do let me know. Thank you for your time and help, it is truly appreciated.
答案1
得分: 0
受到 @ThomasMueller 启发的答案。就像他提到的,“data:application/mp3” 不是有效的数据类型。尽管如此,我通过将URL更改为 data:audio/mpeg;base64,
来实现了我想要的效果。这将生成一个完全空白的 mp3 文件,大小为 0 KB。非常感谢 @ThomasMueller 提供的信息。
英文:
Answer inspired by @ThomasMueller. Like he mentioned, "data:application/mp3" is not a valid data type. That said, I was able to achieve what I wanted by instead changing the URL to data:audio/mpeg;base64,
. This generates a completely empty mp3 file with 0 KB size. Big thanks to @ThomasMueller for the information.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论