javascript - 将 s3.getObject 响应转换为 File 对象

标签 javascript node.js file

我有一个简单的 api,它从代码 await this.s3.getObject(listParams).promise()

以下列格式返回来自 S3.getObject 的响应

S3.getObject response

我如何将其转换为 javascript File对象?

new File([response] as ArrayBuffer, 'test.png') 这样的操作似乎不起作用。正确的转换方法是什么?

最佳答案

解决方法如下

new File([new Uint8Array(response.Body.data) as ArrayBufferView], 'test.png')

关于javascript - 将 s3.getObject 响应转换为 File 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53916171/

相关文章:

javascript - 为什么 valueOf 原型(prototype)函数不起作用

javascript - 使用javascript函数参数影响不同的变量

node.js - postman 401 未经授权 |不能获取

android - Google 登录 - 尝试访问用户信息时出现 401 错误 "Login Required"

android - Android-使用路径获取文件

javascript - 如何使用 javascript 适配器将图像发布到服务器并获取 xml 结果?

javascript - 忽略 react 路由器路由

node.js - 当 mongodb 发生变化时更新客户端中的位置

C - 使用 strtok() 将文件从命令行管道传输到 C 程序

java - 新文件被识别为文件夹