next.js 从s3存储桶查询的输出中读取图像

k10s72fa  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(93)

我上传了一个手动名为userImage.png的图片。但是我不知道如何将输入的结果转换成图像。我从这个问题[how to retrieve image from s3 with nodejs]中得到了一些例子,但我不知道如何使它在aws-sdk-v3中工作。

File: api/route.ts

import { S3Client } from "@aws-sdk/client-s3";
import { GetObjectCommand } from "@aws-sdk/client-s3";

const s3 = new S3Client({ region: process.env.AWS_REGION });

export async function Photo() {
  const command = new GetObjectCommand({
    Bucket: process.env.AWS_BUCKET_NAME,
    Key: "userIcon.png",
  });
  try {
    const data = s3.send(command);
    return data;
  } catch (err) {
    console.log(err);
  }
}

File: page.tsx

import { Photo } from "./api/route";

export default async function Home() {
  const data = await Photo();
  const image = data?.Body;
  console.log(image);
  return (
    <div>
      // I want my incoming image to be inserted here
      <img
        src="https://rpunitpoly.s3.ap-south-1.amazonaws.com/userImage.png"
        alt="iamge"
      />
    </div>
  );
}

控制台日志输出。

- warn ./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
Module not found: Can't resolve '@aws-sdk/signature-v4-crt' in 'D:\Documents\Project\educonnect\node_modules\@aws-sdk\signature-v4-multi-region\dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.shared.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/app/api/aws/route.ts
./src/app/page.tsx

./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in 'D:\Documents\Project\educonnect\node_modules\@aws-sdk\util-user-agent-node\dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/app/api/aws/route.ts
./src/app/page.tsx
<ref *2> IncomingMessage {
  _readableState: ReadableState {
    objectMode: false,
    highWaterMark: 16384,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: [],
    flowing: null,
    ended: false,
    endEmitted: false,
    reading: false,
    constructed: true,
    sync: true,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: true,
    destroyed: false,
    errored: null,
    closed: false,
    closeEmitted: false,
    defaultEncoding: 'utf8',
    awaitDrainWriters: null,
    multiAwaitDrain: false,
    readingMore: true,
    dataEmitted: false,
    decoder: null,
    encoding: null,
    [Symbol(kPaused)]: null
  },
  _events: [Object: null prototype] { end: [Function: responseOnEnd] },
  _eventsCount: 1,
  _maxListeners: undefined,
  socket: <ref *1> TLSSocket {
    _tlsOptions: {
      allowHalfOpen: undefined,
      pipe: false,
      secureContext: [SecureContext],
      isServer: false,
      requestCert: true,
      rejectUnauthorized: true,
      session: undefined,
      ALPNProtocols: undefined,
      requestOCSP: undefined,
      enableTrace: undefined,
      pskCallback: undefined,
      highWaterMark: undefined,
      onread: undefined,
      signal: undefined
    },
    _secureEstablished: true,
    _securePending: false,
    _newSessionPending: false,
    _controlReleased: true,
    secureConnecting: false,
    _SNICallback: null,
    servername: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
    alpnProtocol: false,
    authorized: true,
    authorizationError: null,
    encrypted: true,
    _events: [Object: null prototype] {
      close: [Array],
      end: [Array],
      newListener: [Function: keylogNewListener],
      secure: [Function: onConnectSecure],
      session: [Function (anonymous)],
      free: [Function: onFree],
      timeout: [Array],
      agentRemove: [Function: onRemove],
      error: [Function: socketErrorListener],
      data: [Function: socketOnData],
      drain: [Function: ondrain]
    },
    _eventsCount: 11,
    connecting: false,
    _hadError: false,
    _parent: null,
    _host: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
    _closeAfterHandlingError: false,
    _readableState: ReadableState {
      objectMode: false,
      highWaterMark: 16384,
      buffer: BufferList { head: null, tail: null, length: 0 },
      length: 0,
      pipes: [],
      flowing: true,
      ended: false,
      endEmitted: false,
      reading: true,
      constructed: true,
      sync: false,
      needReadable: true,
      emittedReadable: false,
      readableListening: false,
      resumeScheduled: false,
      errorEmitted: false,
      emitClose: false,
      autoDestroy: true,
      destroyed: false,
      errored: null,
      closed: false,
      closeEmitted: false,
      defaultEncoding: 'utf8',
      awaitDrainWriters: null,
      multiAwaitDrain: false,
      readingMore: false,
      dataEmitted: true,
      decoder: null,
      encoding: null,
      [Symbol(kPaused)]: false
    },
    _maxListeners: undefined,
    _writableState: WritableState {
      objectMode: false,
      highWaterMark: 16384,
      finalCalled: false,
      needDrain: false,
      ending: false,
      ended: false,
      finished: false,
      destroyed: false,
      decodeStrings: false,
      defaultEncoding: 'utf8',
      length: 0,
      writing: false,
      corked: 0,
      sync: false,
      bufferProcessing: false,
      onwrite: [Function: bound onwrite],
      writecb: null,
      writelen: 0,
      afterWriteTickInfo: null,
      buffered: [],
      bufferedIndex: 0,
      allBuffers: true,
      allNoop: true,
      pendingcb: 0,
      constructed: true,
      prefinished: false,
      errorEmitted: false,
      emitClose: false,
      autoDestroy: true,
      errored: null,
      closed: false,
      closeEmitted: false,
      [Symbol(kOnFinished)]: []
    },
    allowHalfOpen: false,
    _sockname: null,
    _pendingData: null,
    _pendingEncoding: '',
    server: undefined,
    _server: null,
    ssl: TLSWrap {
      _parent: [TCP],
      _parentWrap: undefined,
      _secureContext: [SecureContext],
      reading: true,
      onkeylog: [Function: onkeylog],
      onhandshakestart: {},
      onhandshakedone: [Function (anonymous)],
      onocspresponse: [Function: onocspresponse],
      onnewsession: [Function: onnewsessionclient],
      onerror: [Function: onerror],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(owner_symbol)]: [Circular *1]
    },
    _requestCert: true,
    _rejectUnauthorized: true,
    parser: HTTPParser {
      '0': null,
      '1': [Function: parserOnHeaders],
      '2': [Function: parserOnHeadersComplete],
      '3': [Function: parserOnBody],
      '4': [Function: parserOnMessageComplete],
      '5': null,
      '6': null,
      _headers: [],
      _url: '',
      socket: [Circular *1],
      incoming: [Circular *2],
      outgoing: [ClientRequest],
      maxHeaderPairs: 2000,
      _consumed: false,
      onIncoming: [Function: parserOnIncomingClient],
      joinDuplicateHeaders: undefined,
      [Symbol(resource_symbol)]: [HTTPClientAsyncResource]
    },
    _httpMessage: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: true,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [Circular *1],
      _header: 'GET /userIcon.png?x-id=GetObject HTTP/1.1\r\n' +
        'host: rpunitpoly.s3.ap-south-1.amazonaws.com\r\n' +
        'x-amz-user-agent: aws-sdk-js/3.350.0\r\n' +
        'user-agent: aws-sdk-js/3.350.0 ua/2.0 os/win32#10.0.19045 lang/js md/nodejs#20.2.0 api/s3#3.350.0\r\n' +
        'amz-sdk-invocation-id: e719143a-dc05-41eb-8aee-65fe46cc85a5\r\n' +
        'amz-sdk-request: attempt=1; max=3\r\n' +
        'x-amz-date: 20230613T140612Z\r\n' +
        'x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\r\n' +
        'authorization: AWS4-HMAC-SHA256 Credential=AKIAYGZJGWSAIWAUDS5Q/20230613/ap-south-1/s3/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-request;host;x-amz-content-sha256;x-amz-date;x-amz-user-agent, Signature=88daa25c6b306d21d9f86fb635489522a0c04e58cfe5d01e462f2cf9aee7f6b2\r\n' +
        'Connection: keep-alive\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/userIcon.png?x-id=GetObject',
      _ended: false,
      res: [Circular *2],
      aborted: false,
      timeoutCb: [Function: emitRequestTimeout],
      upgradeOrConnect: false,
      parser: [HTTPParser],
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
      protocol: 'https:',
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null
    },
    timeout: 0,
    [Symbol(res)]: TLSWrap {
      _parent: [TCP],
      _parentWrap: undefined,
      _secureContext: [SecureContext],
      reading: true,
      onkeylog: [Function: onkeylog],
      onhandshakestart: {},
      onhandshakedone: [Function (anonymous)],
      onocspresponse: [Function: onocspresponse],
      onnewsession: [Function: onnewsessionclient],
      onerror: [Function: onerror],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(owner_symbol)]: [Circular *1]
    },
    [Symbol(verified)]: true,
    [Symbol(pendingSession)]: null,
    [Symbol(async_id_symbol)]: 1262,
    [Symbol(kHandle)]: TLSWrap {
      _parent: [TCP],
      _parentWrap: undefined,
      _secureContext: [SecureContext],
      reading: true,
      onkeylog: [Function: onkeylog],
      onhandshakestart: {},
      onhandshakedone: [Function (anonymous)],
      onocspresponse: [Function: onocspresponse],
      onnewsession: [Function: onnewsessionclient],
      onerror: [Function: onerror],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(owner_symbol)]: [Circular *1]
    },
    [Symbol(lastWriteQueueSize)]: 0,
    [Symbol(timeout)]: null,
    [Symbol(kBuffer)]: null,
    [Symbol(kBufferCb)]: null,
    [Symbol(kBufferGen)]: null,
    [Symbol(kCapture)]: false,
    [Symbol(kSetNoDelay)]: false,
    [Symbol(kSetKeepAlive)]: true,
    [Symbol(kSetKeepAliveInitialDelay)]: 1,
    [Symbol(kBytesRead)]: 0,
    [Symbol(kBytesWritten)]: 0,
    [Symbol(connect-options)]: {
      rejectUnauthorized: true,
      ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA',
      checkServerIdentity: [Function: checkServerIdentity],
      minDHSize: 1024,
      headers: [Object],
      host: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
      method: 'GET',
      path: null,
      port: 443,
      agent: [Agent],
      auth: undefined,
      _defaultAgent: [Agent],
      keepAlive: true,
      maxSockets: 50,
      noDelay: true,
      servername: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
      _agentKey: 'rpunitpoly.s3.ap-south-1.amazonaws.com:443:::::::::::::::::::::',
      encoding: null,
      keepAliveInitialDelay: 1000
    }
  },
  httpVersionMajor: 1,
  httpVersionMinor: 1,
  httpVersion: '1.1',
  complete: false,
  rawHeaders: [
    'x-amz-id-2',
    'JNhhpCAGEeP6bBpdHHD1uEl0sDs/LJxorRhz4MHe6feppr3RF9nytt4dMfqh6AktnlL19cBxrT+/tbCSGDc3MQ==',
    'x-amz-request-id',
    'DNG7HYSRGGWESYCD',
    'Date',
    'Tue, 13 Jun 2023 14:06:15 GMT',
    'Last-Modified',
    'Tue, 13 Jun 2023 10:31:44 GMT',
    'ETag',
    '"952750a33fd036660df6aba0b770a45d"',
    'x-amz-server-side-encryption',
    'AES256',
    'Accept-Ranges',
    'bytes',
    'Content-Type',
    'image/png',
    'Server',
    'AmazonS3',
    'Content-Length',
    '610377'
  ],
  
    allowHalfOpen: false,
    _sockname: null,
    _pendingData: null,
    _pendingEncoding: '',
    server: undefined,
    _server: null,
    ssl: TLSWrap {
      _parent: [TCP],
      _parentWrap: undefined,
      _secureContext: [SecureContext],
      reading: true,
      onkeylog: [Function: onkeylog],
      onhandshakestart: {},
      onhandshakedone: [Function (anonymous)],
      onocspresponse: [Function: onocspresponse],
      onnewsession: [Function: onnewsessionclient],
      onerror: [Function: onerror],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(owner_symbol)]: [Circular *1]
    },
    _requestCert: true,
    _rejectUnauthorized: true,
    parser: HTTPParser {
      '0': null,
      '1': [Function: parserOnHeaders],
      '2': [Function: parserOnHeadersComplete],
      '3': [Function: parserOnBody],
      '4': [Function: parserOnMessageComplete],
      '5': null,
      '6': null,
      _headers: [],
      _url: '',
      socket: [Circular *1],
      incoming: [Circular *2],
      outgoing: [ClientRequest],
      maxHeaderPairs: 2000,
      _consumed: false,
      onIncoming: [Function: parserOnIncomingClient],
      joinDuplicateHeaders: undefined,
      [Symbol(resource_symbol)]: [HTTPClientAsyncResource]
    },
    _httpMessage: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: true,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [Circular *1],
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/userIcon.png?x-id=GetObject',
      _ended: false,
      res: [Circular *2],
      aborted: false,
      timeoutCb: [Function: emitRequestTimeout],
      upgradeOrConnect: false,
      parser: [HTTPParser],
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
      protocol: 'https:',
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype],
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null
    },
    timeout: 0,
    [Symbol(res)]: TLSWrap {
      _parent: [TCP],
      _parentWrap: undefined,
      _secureContext: [SecureContext],
      reading: true,
      onkeylog: [Function: onkeylog],
      onhandshakestart: {},
      onhandshakedone: [Function (anonymous)],
      onocspresponse: [Function: onocspresponse],
      onnewsession: [Function: onnewsessionclient],
      onerror: [Function: onerror],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(owner_symbol)]: [Circular *1]
    },
    [Symbol(verified)]: true,
    [Symbol(pendingSession)]: null,
    [Symbol(async_id_symbol)]: 1262,
    [Symbol(kHandle)]: TLSWrap {
      _parent: [TCP],
      _parentWrap: undefined,
      _secureContext: [SecureContext],
      reading: true,
      onkeylog: [Function: onkeylog],
      onhandshakestart: {},
      onhandshakedone: [Function (anonymous)],
      onocspresponse: [Function: onocspresponse],
      onnewsession: [Function: onnewsessionclient],
      onerror: [Function: onerror],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(kResourceStore)]: [Object],
      [Symbol(owner_symbol)]: [Circular *1]
    },
    [Symbol(lastWriteQueueSize)]: 0,
    [Symbol(timeout)]: null,
    [Symbol(kBuffer)]: null,
    [Symbol(kBufferCb)]: null,
    [Symbol(kBufferGen)]: null,
    [Symbol(kCapture)]: false,
    [Symbol(kSetNoDelay)]: false,
    [Symbol(kSetKeepAlive)]: true,
    [Symbol(kSetKeepAliveInitialDelay)]: 1,
    [Symbol(kBytesRead)]: 0,
    [Symbol(kBytesWritten)]: 0,
    [Symbol(connect-options)]: {
      rejectUnauthorized: true,
      checkServerIdentity: [Function: checkServerIdentity],
      minDHSize: 1024,
      headers: [Object],
      host: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
      method: 'GET',
      path: null,
      port: 443,
      agent: [Agent],
      auth: undefined,
      _defaultAgent: [Agent],
      keepAlive: true,
      maxSockets: 50,
      noDelay: true,
      servername: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
      _agentKey: 'rpunitpoly.s3.ap-south-1.amazonaws.com:443:::::::::::::::::::::',
      encoding: null,
      keepAliveInitialDelay: 1000
    }
  },
  _consuming: false,
  _dumped: false,
  req: <ref *3> ClientRequest {
    _events: [Object: null prototype] {
      error: [Function (anonymous)],
      socket: [Array],
      timeout: [Function],
      finish: [Function: requestOnFinish]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: true,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: false,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    strictContentLength: false,
    _contentLength: 0,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: <ref *1> TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 11,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
      _closeAfterHandlingError: false,
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: [HTTPParser],
      _httpMessage: [Circular *3],
      timeout: 0,
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 1262,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: true,
      [Symbol(kSetKeepAliveInitialDelay)]: 1,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object]
    },
    _header: 'GET /userIcon.png?x-id=GetObject HTTP/1.1\r\n' +
      'host: rpunitpoly.s3.ap-south-1.amazonaws.com\r\n' +
      'x-amz-user-agent: aws-sdk-js/3.350.0\r\n' +
      'user-agent: aws-sdk-js/3.350.0 ua/2.0 os/win32#10.0.19045 lang/js md/nodejs#20.2.0 api/s3#3.350.0\r\n' +
      'amz-sdk-invocation-id: e719143a-dc05-41eb-8aee-65fe46cc85a5\r\n' +
      'amz-sdk-request: attempt=1; max=3\r\n' +
      'x-amz-date: 20230613T140612Z\r\n' +
      'x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\r\n' +
      'authorization: AWS4-HMAC-SHA256 Credential=AKIAYGZJGWSAIWAUDS5Q/20230613/ap-south-1/s3/aws4_request, SignedHeaders=amz-sdk-invocation-id;amz-sdk-request;host;x-amz-content-sha256;x-amz-date;x-amz-user-agent, Signature=88daa25c6b306d21d9f86fb635489522a0c04e58cfe5d01e462f2cf9aee7f6b2\r\n' +
      'Connection: keep-alive\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: true,
      maxSockets: 50,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'GET',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    joinDuplicateHeaders: undefined,
    path: '/userIcon.png?x-id=GetObject',
    _ended: false,
    res: [Circular *2],
    aborted: false,
    timeoutCb: [Function: emitRequestTimeout],
    upgradeOrConnect: false,
    parser: HTTPParser {
      '0': null,
      '1': [Function: parserOnHeaders],
      '2': [Function: parserOnHeadersComplete],
      '3': [Function: parserOnBody],
      '4': [Function: parserOnMessageComplete],
      '5': null,
      '6': null,
      _headers: [],
      _url: '',
      socket: [TLSSocket],
      incoming: [Circular *2],
      outgoing: [Circular *3],
      maxHeaderPairs: 2000,
      _consumed: false,
      onIncoming: [Function: parserOnIncomingClient],
      joinDuplicateHeaders: undefined,
      [Symbol(resource_symbol)]: [HTTPClientAsyncResource]
    },
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'rpunitpoly.s3.ap-south-1.amazonaws.com',
    protocol: 'https:',
    [Symbol(kCapture)]: false,
    [Symbol(kBytesWritten)]: 0,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      host: [Array],
      'x-amz-user-agent': [Array],
      'user-agent': [Array],
      'amz-sdk-invocation-id': [Array],
      'amz-sdk-request': [Array],
      'x-amz-date': [Array],
      'x-amz-content-sha256': [Array],
      authorization: [Array]
    },
    [Symbol(errored)]: null,
    [Symbol(kHighWaterMark)]: 16384,
    [Symbol(kRejectNonStandardBodyWrites)]: false,
    [Symbol(kUniqueHeaders)]: null
  },
  transformToByteArray: [AsyncFunction: transformToByteArray],
  transformToString: [AsyncFunction: transformToString],
  transformToWebStream: [Function: transformToWebStream],
  [Symbol(kCapture)]: false,
  [Symbol(kHeaders)]: {
    'x-amz-id-2': 'JNhhpCAGEeP6bBpdHHD1uEl0sDs/LJxorRhz4MHe6feppr3RF9nytt4dMfqh6AktnlL19cBxrT+/tbCSGDc3MQ==',
    'x-amz-request-id': 'DNG7HYSRGGWESYCD',
    date: 'Tue, 13 Jun 2023 14:06:15 GMT',
    'last-modified': 'Tue, 13 Jun 2023 10:31:44 GMT',
    etag: '"952750a33fd036660df6aba0b770a45d"',
    'x-amz-server-side-encryption': 'AES256',
    'accept-ranges': 'bytes',
    'content-type': 'image/png',
    server: 'AmazonS3',
    'content-length': '610377'
  },
  [Symbol(kHeadersCount)]: 20,
  [Symbol(kTrailers)]: null,
  [Symbol(kTrailersCount)]: 0
}
{ data: undefined, status: 'loading', update: [Function: update] }
- warn ./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
Module not found: Can't resolve '@aws-sdk/signature-v4-crt' in 'D:\Documents\Project\educonnect\node_modules\@aws-sdk\signature-v4-multi-region\dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.shared.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/app/api/aws/route.ts
./src/app/page.tsx

./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in 'D:\Documents\Project\educonnect\node_modules\@aws-sdk\util-user-agent-node\dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/app/api/aws/route.ts
./src/app/page.tsx
- wait compiling /api/auth/[...nextauth]/route (client and server)...
- warn ./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
Module not found: Can't resolve '@aws-sdk/signature-v4-crt' in 'D:\Documents\Project\educonnect\node_modules\@aws-sdk\signature-v4-multi-region\dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.shared.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/app/api/aws/route.ts
./src/app/page.tsx

./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in 'D:\Documents\Project\educonnect\node_modules\@aws-sdk\util-user-agent-node\dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/app/api/aws/route.ts
./src/app/page.tsx

包详情

| Package 名称|版本|
| - -----|- -----|
| NodeJS| 20.2|
| @aws-sdk/client-s3| 3.350.0|
| NextJS| 13.4.5|

l7wslrjt

l7wslrjt1#

S3存储桶是否可公开访问?如果是,您应该可以直接使用<img src='<s3_bucket_url>/userIcon.png' />显示图像。
如果S3存储桶不可公开访问,请生成一个预签名URL,如本article所述,并使用生成的URL使用<img src='<generated_presigned_url>' />显示图像

相关问题