How to get a raw response like XML using s3 client from aws/sdk-javascript.

0

When I execute ListBucketscommand() using the SDK's S3 client, you can get the following result. How to get a raw response like XML using s3 client from aws/sdk.

// sample code & result const command = new ListBucketsCommand({}); const response = await client.send(command); console.log(response); '$metadata': { httpStatusCode: 200, requestId: '1759FE4B14A997E0', extendedRequestId: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', cfId: undefined, attempts: 1, totalRetryDelay: 0 }, Buckets: [ { Name: 'test', CreationDate: 2023-03-13T04:45:29.702Z }, { Name: 'test-0424', CreationDate: 2023-04-24T03:25:08.831Z }, ]

// xml format

<?xml version="1.0" encoding="UTF-8"?> <ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Owner> <DisplayName>minio</DisplayName> <ID>02d6176db174dc93cb1b899f7c6078f08654445fe8cf1b6ce98d8855f66bdbf4</ID> </Owner> <Buckets> <Bucket> <Name>test</Name> <CreationDate>2023-03-13T04: 45: 29.702Z</CreationDate> </Bucket> <Bucket> <Name>test-0424</Name> <CreationDate>2023-04-24T03: 25: 08.831Z</CreationDate> </Bucket> </Buckets> </ListAllMyBucketsResult>
질문됨 일 년 전1008회 조회
2개 답변
1

The SDK parses the raw XML responses from the S3 API and converts them into JavaScript objects before returning them to the user.

https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-select.html

But you can directly query S3 API

https://docs.aws.amazon.com/AmazonS3/latest/API/API_SelectObjectContent.html

You can use axios library to do this.

profile picture
전문가
답변함 일 년 전
1

For AWS SDK for JavaScript v2, you can access the raw response via the response field on the request object. Note that response field on the request object will not be set until after the request has been completed, thus the need to await in the example below before accessing.

const listBucketsRequest = S3.listBuckets({});
const listBucketsResponse = await listBucketsRequest.promise()
console.log(listBucketsRequest.response.httpResponse.body.toString());

If AWS SDK for JavaScript v3 does not expose a similar set of objects. Access to the raw response would be done at the middleware level:

profile pictureAWS
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠