{"id":9319,"date":"2025-08-25T17:21:24","date_gmt":"2025-08-25T11:51:24","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=9319"},"modified":"2025-08-25T17:21:28","modified_gmt":"2025-08-25T11:51:28","slug":"a-guide-to-upload-images-to-s3","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/a-guide-to-upload-images-to-s3\/","title":{"rendered":"A Guide to upload Images to S3"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Introduction:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">S3 (Simple Storage Service) is a cloud storage platform for handling file uploads, especially images. Whenever a mobile app or web application is developed, we need a reliable image storage solution. S3 provides scalable, secure and cost-effective storage with high performance.<br>In this blog, we can see the different approaches to upload images to s3.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why S3 storage?<\/strong><br>This storage has lot of advantages:<br><strong><em>Scalability:<\/em><\/strong> Handles millions of images<br><strong><em>Durability: <\/em><\/strong>Has 99.99% data durability<br><strong><em>Global CDN Integration:<\/em><\/strong> Very easily intehrated for fast image delivery<br><strong><em>Cost-Effective:<\/em><\/strong> Pay only for what we use<br><strong><em>Security:<\/em><\/strong> Fine-grained access control and encryption options<br><strong><em>Integration: <\/em><\/strong>Works without any issues with other AWS services<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prerequisites:<\/strong><br>Before we start integrating, we must ensure we are having the following details.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>An AWS account with s3 access<\/li>\n\n\n\n<li>AWS Credentials (Access Key ID &amp; secret Access key)<\/li>\n\n\n\n<li>An S3 bucket created<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Direct Upload from client-Side<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This can be easily done by using simple java script utility function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Step 1:<\/em><\/strong> Install AWS SDK. The command is npm install aws-sdk.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Step 2:<\/em><\/strong><br>Basic Client side Upload:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Import the installed package.<br>import AWS from &#8216;aws-sdk&#8217;;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have to configure AWS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">AWS.config.update({<br>accessKeyId: &#8216;YOUR_ACCESS_KEY&#8217;,<br>secretAccessKey: &#8216;YOUR_SECRET_KEY&#8217;,<br>region: &#8216;REGION USED WHILE CREATION&#8217;<br>});<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Step 3:<\/em><\/strong><br>const s3 = new AWS.S3();<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">function uploadImage(file, bucketName, key) {<br>const params = {<br>Bucket: bucketName,<br>Key: key,<br>Body: file,<br>ContentType: file.type,<br>ACL: &#8216;public-read&#8217; \/\/ Make the file publicly accessible<br>};<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">return s3.upload(params).promise();<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const result = await uploadImage(file, &#8216;your-bucket-name&#8217;, <code>images\/${Date.now()}-${file.name}<\/code>);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If we call the function with the required parameters we can save the images in S3 bucket we have created.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Server-Side Upload:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Server-side uploads can be done by using Node.js or Express. It is a better security process.<br><strong><em>Step 1:<\/em><\/strong><br>Setting Up Express Server.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server1.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"805\" height=\"357\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server1.png\" alt=\"\" class=\"wp-image-9324\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server1.png 805w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server1-300x133.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server1-768x341.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server1-676x300.png 676w\" sizes=\"(max-width: 805px) 100vw, 805px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server2-1.png\"><img decoding=\"async\" width=\"762\" height=\"416\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server2-1.png\" alt=\"\" class=\"wp-image-9325\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server2-1.png 762w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server2-1-300x164.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server2-1-550x300.png 550w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Step 2:<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Upload images.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server3.png\"><img decoding=\"async\" width=\"780\" height=\"810\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server3.png\" alt=\"\" class=\"wp-image-9326\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server3.png 780w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server3-289x300.png 289w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server3-768x798.png 768w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Predesigned URLs:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is a more secure way to allow direct client uploads without exposing AWS credentials.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here attached steps to create a URL on both client and server side respectively.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"878\" height=\"628\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server4.png\" alt=\"\" class=\"wp-image-9327\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server4.png 878w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server4-300x215.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server4-768x549.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server4-419x300.png 419w\" sizes=\"(max-width: 878px) 100vw, 878px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server5.png\"><img loading=\"lazy\" decoding=\"async\" width=\"782\" height=\"827\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server5.png\" alt=\"\" class=\"wp-image-9328\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server5.png 782w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server5-284x300.png 284w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2025\/08\/server5-768x812.png 768w\" sizes=\"(max-width: 782px) 100vw, 782px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Advanced Features:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We can also advanced features like Image optimization and resizing for better performance.<\/li>\n\n\n\n<li>We can also include progress tracking during file upload process.<\/li>\n\n\n\n<li>Multiple file uploads are handled.<\/li>\n\n\n\n<li>Improved error handling and validation<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Best Practices:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Considering security purposes we should always store keys as environemntal variables and should not use directly in our code either client-side or server-side.<\/li>\n\n\n\n<li>We should follow performance optimization methods.<\/li>\n\n\n\n<li>To track the progress we should include the error handling techniques.       <\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Using these methods, we can upload images to cloud storage and can preserve them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: S3 (Simple Storage Service) is a cloud storage platform for handling file uploads, especially images. Whenever a mobile app [&hellip;]<\/p>\n","protected":false},"author":502,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[],"class_list":["post-9319","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2qj","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/502"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=9319"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9319\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=9319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=9319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=9319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}