简体   繁体   English

什么是AWS S3桶响应中的Unit8Array

[英]What's Unit8Array in AWS S3 bucket response

I am calling the AWS S3 getObject function: (AWS.Request) getObject(params = {}, callback) 我正在调用AWS S3 getObject函数: (AWS.Request) getObject(params = {}, callback)

I wrote this: 我写了这个:

getMenuJson() {
   this.s3.getObject({
     Bucket: 'improd-image-pipeline',
     Key: 'remoteUX/qa/menus/v1/menus.json',
     ResponseContentType: 'application/json',
   }, (err, data) => {
     if (err) {
       this.$log.log(err);
     } else {
       this.$log.log(data, JSON.parse(data.Body));
     }
   });
 }

This is the console output, I try to print the data and the actual menus.json file on the S3 console. 这是控制台输出,我尝试在S3控制台上打印数据和实际的menus.json文件。 在此输入图像描述

The return data if I printed like this: JSON.parse(data.Body), this is the result. 如果我这样打印返回数据:JSON.parse(data.Body),这就是结果。

 {  
   "menus":[  
      {  
         "name": "Flat Collections Example",
         "menuId": "aaa-3656-4a32-bdda-e2e016cf35ee"
      },
      {  
         "name":"P3",
         "menuId": "aaa-f5fc-4e18-9089-47e43a4237e8"
      },
      {  
         "name": "Tabbed Menu Example",
         "menuId": "aaa-768a-40bd-a9f4-b633f3679c36"
      }
   ]
}

But, how to understand the response body: Unit8Array, and how it's interpreted to a actual json formatted data? 但是,如何理解响应体:Unit8Array,以及如何将其解释为实际的json格式数据?

I am using Angular.toJson(data.Body) and this function didn't understand it, but JSON.parse(data.Body) will get the correct result. 我正在使用Angular.toJson(data.Body)并且此函数不理解它,但JSON.parse(data.Body)将获得正确的结果。

It's a JavaScript Typed Array which represents an array of 8-bit unsigned integers. 它是一个JavaScript类型数组,表示一个8位无符号整数数组。

AWS.Request.getObject() return value of data.Body can be any of the following: Buffer, Typed Array, Blob, String, ReadableStream. AWS.Request.getObject()返回data.Body的值可以是以下任何一种:Buffer,Typed Array,Blob,String,ReadableStream。

You can check AWS docs for more info. 您可以查看AWS文档以获取更多信息。

In your case it's Uint8Array (JavaScript typed array). 在你的情况下,它是Uint8Array (JavaScript类型数组)。

Understand more: JavaScript Typed Arrays , Uint8Array object 了解更多: JavaScript Typed ArraysUint8Array对象

I would recommend to use AWS SDK for javascript. 我建议使用AWS SDK for javascript。 http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/working-with-json.html http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/working-with-json.html

The AWS SDK for JavaScript provides a JavaScript API for AWS services. AWS SDK for JavaScript为AWS服务提供JavaScript API。 Using the SDK, you can build JavaScript applications for the browser. 使用SDK,您可以为浏览器构建JavaScript应用程序。 The JavaScript API allows developers to build libraries or applications that make use of AWS services. JavaScript API允许开发人员构建使用AWS服务的库或应用程序。

The script to use is here: https://sdk.amazonaws.com/js/aws-sdk-2.6.10.min.js 要使用的脚本位于: https//sdk.amazonaws.com/js/aws-sdk-2.6.10.min.js

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

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