1)我正在尝试解码类似 abb197313b83ad9f16a946c8be35a0f8 的GET请求但是我收到此错误。
TypeError:第一个参数必须是字符串,Buffer,ArrayBuffer,Array或类似数组的对象。
let decoder;
const parseMetadataString = (metadata_string) => {
const kv_pair_list = metadata_string.split(',');
return kv_pair_list.reduce((metadata, kv_pair) => {
const [key, base64_value] = kv_pair.split(' ');
metadata[key] = {
encoded: base64_value,
decoded: Buffer.from(base64_value, 'base64').toString('ascii'),
};
return decoder = metadata;
}, {});
}
app.get('/upload/files/:fileid', (req, res) => {
const { fileid } = req.params;
parseMetadataString(fileid);
res.sendFile(__dirname + /files/ + decoder);
});
2)如果我这样做,我会收到此错误:
TypeError:无法读取未定义的属性“name”
但它确实使用正确的名称res.sendFile。
let decoder;
const parseMetadataString = (metadata_string) => {
const kv_pair_list = metadata_string.split(',');
return kv_pair_list.reduce((metadata, kv_pair) => {
const [key, base64_value] = kv_pair.split(' ');
metadata[key] = {
encoded: base64_value,
decoded: Buffer.from(base64_value, 'base64').toString('ascii'),
};
return decoder = metadata;
}, {});
}
app.get('/upload/files/:fileid', (req, res) => {
const { fileid } = req.params;
res.sendFile(__dirname + /files/ + decoder.name.decoded);
});
server.on(EVENTS.EVENT_UPLOAD_COMPLETE, (event) => {
parseMetadataString(event.file.upload_metadata);
});