在 IBM Cloud Function 中发送 zip 文件作为响应
Send zip file as response in IBM Cloud Function
我在 IBM Cloud Functions 中部署了一个无服务器函数。该函数生成并下载 excel 文件。
在本地它按预期工作,但在部署版本上我收到以下错误:
{
"code": "xxxxxxxxxx",
"error": "Response type in header did not match generated content type."
}
使用 Content-Type header 'application/json'
我可以发送 json 和 'image/png'
甚至图像作为 base64。 Zip 文件不工作。我试过 'Content-Type': 'application/zip
和 'Content-Type': 'application/zip, application/octet-stream
我需要做更多的配置吗?
完整示例:
headers: {
'Content-Type': 'application/zip',
'Content-Disposition': `attachment; filename=foo.zip;`,
'Content-Transfer-Encoding': 'binary',
'Content-Length': zip.length
},
我通过生成 base64 zip 而不是 uint8array 来修复它。
之前:
var JSZip = require("jszip");
var zip = new JSZip();
const myZip = await zip.generateAsync({
type: 'uint8array',
base64: true,
compression: 'DEFLATE'
});
之后:
var JSZip = require("jszip");
var zip = new JSZip();
const myZip = await zip.generateAsync({type: 'base64'});
我在 IBM Cloud Functions 中部署了一个无服务器函数。该函数生成并下载 excel 文件。
在本地它按预期工作,但在部署版本上我收到以下错误:
{
"code": "xxxxxxxxxx",
"error": "Response type in header did not match generated content type."
}
使用 Content-Type header 'application/json'
我可以发送 json 和 'image/png'
甚至图像作为 base64。 Zip 文件不工作。我试过 'Content-Type': 'application/zip
和 'Content-Type': 'application/zip, application/octet-stream
我需要做更多的配置吗?
完整示例:
headers: {
'Content-Type': 'application/zip',
'Content-Disposition': `attachment; filename=foo.zip;`,
'Content-Transfer-Encoding': 'binary',
'Content-Length': zip.length
},
我通过生成 base64 zip 而不是 uint8array 来修复它。
之前:
var JSZip = require("jszip");
var zip = new JSZip();
const myZip = await zip.generateAsync({
type: 'uint8array',
base64: true,
compression: 'DEFLATE'
});
之后:
var JSZip = require("jszip");
var zip = new JSZip();
const myZip = await zip.generateAsync({type: 'base64'});