我有一个带有2个链接的网站。一个下载MP3,一个下载WAV文件
例如:
<a href="https://mywesbite.com/download?file=//assets.net/beethoven-fur-elise.wav" download="beethoven-fur-elise">Download WAV</a>
和
<a href="https://mywesbite.com/download?file=//assets.net/beethoven-fur-elise.mp3" download="beethoven-fur-elise">Download MP3</a>
我已经为/ download /编写了一个云函数,该函数将发送远程音频文件,因此将提示用户下载该文件,并且无法在新标签页中打开它并播放。
MP3 链接可用,但 WAV 文件失败,并且错误日志显示
Error: incorrect function response. Function invocation was interrupted.
Function execution took 2941 ms, finished with status: 'response error'
请注意,在我的本地计算机上,WAV和MP3均可工作。
MP3
文件大约为 3-6 MB
WAV
文件大约为 40 MB
const express = require('express');
const request = require('request');
const cors = require('cors');
const helmet = require('helmet');
const downloadApp = express();
downloadApp.use(helmet());
downloadApp.use(
cors({
origin: true
})
);
downloadApp.get('/download', (req, res) => {
res.set(
'Cache-control',
`public, max-age=${CONFIG.TIME.CACHE_IN_USERS_BROWSER}, s-maxage=${
CONFIG.TIME.CACHE_IN_CDN
}`
);
/**
*
* contentType = 'audio/wav'
* OR
* contentType = 'audio/mpeg'
*
* */
res.setHeader('Content-Type', contentType);
res.setHeader('Content-disposition', `attachment; filename="${filename}"`);
// External URL to MP3 or WAV
const externalUrl = 'https://external-website.com/something.wav';
request
.get(externalUrl)
.on('error', function(err) {
console.error('Download Error: ', err);
})
.pipe(res);
});
答案 0 :(得分:1)
我遇到了一个类似的问题,最终发现失败与here中所述的配额和限制有关。
我的所有云功能都无法响应> 10MB。
答案 1 :(得分:0)
Google Cloud Functions配额:
最大未压缩HTTP响应大小=每次调用10MB
最大未压缩HTTP请求大小=每次调用10MB