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
Tweet

More Decks by Jeremy Lindblom

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. ❖ Regions ❖ Buckets ❖ Objects ❖ Keys ❖ ACLs

    S3 - Is “private” by default - Set to “public-read” for public access us-west-1
  4. 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
  5. “ 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
  6. 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
  7. Place your screenshot here The Four Ways ◇ Superglobals +

    AWS SDK ◇ PSR-7 + AWS SDK ◇ PSR-7 + Flysystem ◇ PSR-7 + PostObject 13