使用Deno和Hono从S3下载文件时触发OUT_OF_RANGE错误的问题求助
Deno和Hono从S3下载文件时触发OUT_OF_RANGE错误的问题求助
我现在遇到一个特别头疼的问题:用Deno搭配Hono框架从S3下载文件时,总是返回500错误,错误类型是OUT_OF_RANGE。更郁闷的是,这套逻辑在Node.js环境下完全能正常运行,迁移到Deno后就出问题了。
我搜遍了全网都没找到解决方案,大部分Deno的S3库都已经过时没法用了,但S3的其他操作比如上传在Deno里都能完美运行,所以我觉得下载功能应该不是Deno本身的问题。
以下是我的核心代码:
下载服务函数
export async function downloadFileService(path: string, c: Context) { try { const command = new GetObjectCommand({ Bucket: "sharesbucket", Key: path, }); const response = await s3Client.send(command); // 我90%确定问题就出在这部分代码里 const data = await response.Body?.transformToByteArray(); if (!data) { return c.json({ message: "File not found" }, 404); } c.header('Content-Type', 'application/octet-stream'); c.header('Content-Disposition', `attachment;`); return c.body(data); } catch (err) { return c.json({ message: "Server error has occured", error: err, }, 500); } }
路由定义(示例:/v1/download)
downloadRoute.post("/", async (c) => { const { path } = await c.req.json(); return await downloadFileService(path, c); });
我已经试过求助各种大模型,但它们给出的方案都陷入了循环,根本解决不了实际问题;也全网搜索过相关问题,但完全找不到任何有效的答案。有没有人遇到过类似的问题,或者能帮我定位一下到底是哪里出了问题?
内容来源于stack exchange
相关产品推荐
相关产品推荐

