Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Uploading to S3 from PHP

Uploading to S3 from PHP

Working with the Amazon S3 service is pretty easy if you understand the basic concepts of S3 and are using one of the AWS-provided SDKs, like the AWS SDK for PHP. This presentation and corresponding demo code will show you how it's done.


Jeremy Lindblom

July 24, 2018

More Decks by Jeremy Lindblom

Other Decks in Programming


  1. « S3 Upload Demo » & more 2018.07.24 azPHP

  2. Hello! I’m Jeremy Lindblom Software Architect at McGraw-Hill Education @jeremeamia

    on Twitter and GitHub 2
  3. Uploading to S3 from PHP We will use the AWS

    SDK for PHP to upload a file to S3 also dive into the details about S3, AWS, the SDK, & Guzzle 3
  4. Tell me about “all the things”! Amazon S3 A blob

    storage cloud-based service provided by AWS. First released in 2006. Very popular, and has tons of features. Blob Storage A service for storing and retrieving “blob”s, or “object”s, which are essentially chunks of text or binary data. We typically call these “files” locally. AWS Amazon Web Services. A large suite of web services and APIs for manipulating data and infrastructure in Amazon’s cloud. AWS SDK for PHP An AWS-supported PHP library for interacting AWS’s services and APIs. It is built on Guzzle. Guzzle A popular HTTP client library for PHP that implements PSR-7 and middleware, and provides an abstraction layer over cURL. PSR-7 A PSR (PHP Standards Recommendation) created by the PHP-FIG to define standard interfaces for HTTP Request and Response objects. 4
  5. AWS Has a BIG Problem Hint: It’s not their competition.

  6. 6 They’re BIG!

  7. Over 100 different services spread across 18+ categories 7

  8. Almost Everything Else Many of their services build on each

    other EC2 S3 8
  9. ❖ Regions ❖ Buckets ❖ Objects ❖ Keys ❖ ACLs

    S3 - Is “private” by default - Set to “public-read” for public access us-west-1
  10. Keys & Prefixes https://{bucket}.s3-{region}.amazonaws.com/{key} ◇ region: The AWS region (e.g.,

    us-east-1, us-west-2) ◇ bucket: Your bucket name (they are globally unique) ◇ key: Path to the specific object in the bucket A prefix is the first part of a path key. Usually used to represent a “directory” (e.g., foo/bar/baz.json). When you list objects, you list them by a prefix. 10
  11. “ Performance scales per prefix, so you can use as

    many prefixes as you need in parallel to achieve the required throughput. There are no limits to the number of prefixes. 11
  12. Let’s Look at Some Code! We will look at four

    ways that an upload to S3 can be performed in a PHP application using the AWS SDK for PHP and other libraries. Demo
  13. Place your screenshot here The Four Ways ◇ Superglobals +

    AWS SDK ◇ PSR-7 + AWS SDK ◇ PSR-7 + Flysystem ◇ PSR-7 + PostObject 13
  14. 14 goto the_code; https://github.com/jeremeamia/azphp-s3-upload-demo

  15. Thanks! Any questions? You can find me at: ◇ @jeremeamia

    ◇ jeremeamia@gmail.com 15
  16. Resources ◇ https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-presigned-post.html ◇ https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPOST.html#RESTObjectPOST-requests-examples ◇ https://fontawesome.com/ ◇ https://getbootstrap.com/ ◇

    https://ngrok.com/ ◇ http://flysystem.thephpleague.com/docs/ 16
  17. Credits ◇ Presentation template by SlidesCarnival 17