{"id":3784,"date":"2022-12-31T13:03:30","date_gmt":"2022-12-31T04:03:30","guid":{"rendered":"https:\/\/dennie.tokyo\/it\/?p=3784"},"modified":"2022-12-31T13:11:56","modified_gmt":"2022-12-31T04:11:56","slug":"aws-s3-node-js-%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89","status":"publish","type":"post","link":"https:\/\/dennie.tokyo\/it\/?p=3784","title":{"rendered":"AWS S3 node js \u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9"},"content":{"rendered":"\n<p>S3 \u30d0\u30b1\u30c3\u30c8\u3078\u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u884c\u3044\u307e\u3059\u3002<br>node js \u306b\u3066 AWS SDK\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h1 class=\"wp-block-heading\">\u524d\u63d0<\/h1>\n\n\n\n<p>AWS SDK \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>npm install @aws-sdk\/client-s3<\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">\u30b5\u30f3\u30d7\u30eb<\/h1>\n\n\n\n<p>node\u3092\u4f7f\u7528\u3059\u308b\u306e\u3067 AWS SDK for javascript \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br>PutObjectCommand\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-file=\"index.mjs\" data-lang=\"JavaScript\"><code>import { S3Client, PutObjectCommand} from &quot;@aws-sdk\/client-s3&quot;;\nimport fs from &quot;fs&quot;;\n\n\/\/ S3 \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u751f\u6210\u3059\u308b\u3002\nconst S3ClientInput = {\n    region: &#39;ap-northeast-1&#39;,\n    credentials: {\n        accessKeyId: &#39;\u30a2\u30af\u30bb\u30b9\u30ad\u30fc&#39;,\n        secretAccessKey:&#39;\u30b7\u30fc\u30af\u30ec\u30c3\u30c8\u30a2\u30af\u30bb\u30b9\u30ad\u30fc&#39;,\n    },\n}\nconst client = new S3Client(S3ClientInput);\n\n\/\/ S3 \u30d0\u30b1\u30c3\u30c8\u3078\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u305f\u3044\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u3002\nconst img = fs.readFileSync(&quot;test.jpg&quot;);\n\n\/\/ S3 \u30d0\u30b1\u30c3\u30c8\u3078\u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u884c\u3046\u30b3\u30de\u30f3\u30c9(PutObjectCommand)\u3092\u751f\u6210\u3059\u308b\u3002\nconst input  = {\n    Bucket: &#39;\u30d0\u30b1\u30c3\u30c8\u540d&#39;,\n    Key: &#39;\u30ad\u30fc\u540d&#39;,\n    Body: img,\n};\nconst command = new PutObjectCommand(input);\n\n\/\/ S3 \u30d0\u30b1\u30c3\u30c8\u3078\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u3002\nconst res = await client.send(command);<\/code><\/pre><\/div>\n\n\n\n<p>\u306a\u304a\u3001\u30ad\u30fc\u540d\u306b &#8220;\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9\/\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30ad\u30fc&#8221; \u3068\u3059\u308b\u3053\u3068\u3067\u30d7\u30ec\u30d5\u30a3\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>S3 \u30d0\u30b1\u30c3\u30c8\u3078\u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u884c\u3044\u307e\u3059\u3002node js \u306b\u3066 AWS SDK\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":957,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,31],"tags":[],"class_list":["post-3784","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","category-s3"],"_links":{"self":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3784","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3784"}],"version-history":[{"count":4,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3784\/revisions"}],"predecessor-version":[{"id":3790,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/posts\/3784\/revisions\/3790"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=\/wp\/v2\/media\/957"}],"wp:attachment":[{"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dennie.tokyo\/it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}