简体   繁体   English

解码在Javascript中编码为缓冲区的文件

[英]Decoding File Encoded as Buffer In Javascript

I am downloading an item from an S3 bucket using getObject. 我正在使用getObject从S3存储桶下载项目。 I am able to receive the object as a JSON object with the correct ContentType of 'image/jpeg'. 我可以使用正确的ContentType为'image / jpeg'的JSON对象形式接收该对象。 The picture data is encoded as in something I am not familiar with. 图片数据被编码为我不熟悉的东西。 It starts with 它开始于

<Buffer ff d8 ff e0 00 10 4a 46

And goes on for a large number of lines. 并继续进行大量的线路。 Calling JSON.stringify on the entire object converts the 在整个对象上调用JSON.stringify会转换

"type": "Buffer",
      "data": [
        137,80,78,71,13,10,26,10,

I am not familiar with how I should decode this in order to display an image given the ContentType information and the image data. 我不熟悉如何解码此内容以显示具有ContentType信息和图像数据的图像。 How do I convert the data into an image that I can display using a URL source tag? 如何将数据转换为可以使用URL源标记显示的图像?

I don't want to display the image directly from the source because I am trying to download the image and save it to local storage for display when the user is offline. 我不想直接从源显示图像,因为我正在尝试下载图像并将其保存到本地存储中以供用户离线时显示。

The image will be displayed in a react-native application using the component. 该图像将使用该组件在本机应用程序中显示。

您将需要在本地编写它,或者使用具有正确mimetype的流直接发送它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM