How is this AWS `PutObjectCommand` uploading the file I have sent?

I am trying out a new tool called SST which handles configuring AWS services and full stack web apps via code. In the API tutorial we create the following function to upload a file:

import { Resource } from "sst";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import {
  S3Client,
  GetObjectCommand,
  PutObjectCommand,
  ListObjectsV2Command,
} from "@aws-sdk/client-s3";

const s3 = new S3Client({});

export async function upload() {
  const command = new PutObjectCommand({
    Key: crypto.randomUUID(),
    Bucket: Resource.MyBucket.name,
  });
  const body = await getSignedUrl(s3, command);

  return {
    statusCode: 200,
    body
  };
}

That is the entire upload function. As you can see there is no explicit handling of any files – I had initially thought this would create an empty file in the specified S3 bucket.

Next, once our server is live we send a curl request with a file to upload:

curl --upload-file somefile.txt "$(curl https://sometestapi.execute-api.eu-west-1.amazonaws.com)"

However when I check the S3 bucket via the AWS console I can see somefile.txt and all its content is there. I’m really not understanding a) how this file is being picked up by the API – there is nothing explicit going on here, and b) how this file is then being sent to S3.

Logging command and body I see the following:

|  +26ms       {
|  +26ms         command: PutObjectCommand {
|  +26ms           middlewareStack: {
|  +26ms             add: [Function: add],
|  +26ms             addRelativeTo: [Function: addRelativeTo],
|  +26ms             clone: [Function: clone],
|  +26ms             use: [Function: use],
|  +26ms             remove: [Function: remove],
|  +26ms             removeByTag: [Function: removeByTag],
|  +26ms             concat: [Function: concat],
|  +26ms             applyToStack: [Function: cloneTo],
|  +26ms             identify: [Function: identify],
|  +26ms             identifyOnResolve: [Function: identifyOnResolve],
|  +26ms             resolve: [Function: resolve]
|  +26ms           },
|  +26ms           serialize: [AsyncFunction: se_PutObjectCommand],
|  +26ms           deserialize: [AsyncFunction: de_PutObjectCommand],
|  +26ms           input: {
|  +26ms             Key: '860d1393-4232-48fc-4d4b-b42c0c8a6473',
|  +26ms             Bucket: 'mytestprojectname-testbucket-tokfzzao'
|  +26ms           }
|  +26ms         }
|  +26ms       }
|  +26ms       {
|  +26ms         body: 'https://mytestprojectname-testbucket-tokfzzao.s3.eu-west-1.amazonaws.com/860d1393-4232-48fc-9d4a-b42c0c8a6473?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=<removed-credentials>&X-Amz-Date=20240607T170451Z&X-Amz-Expires=900&X-Amz-Security-Token=<removed-security-token>&X-Amz-Signature=<removed-signature>&X-Amz-SignedHeaders=host&x-id=PutObject'
|  +26ms       }

I have tried debugging all the available variables in the function to see if any contain the file being uploaded, but neither do. I had expected since no file is being explicitly handled it would not be uploaded to S3.

New contributor

Josh Jahans is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật