CyberJunkie
CyberJunkie

Reputation: 22684

amazon s3 get object info from upload response

I'm uploading images to amazon s3 using PHP. When I upload a file I want to store information about it in my database so I'll make less API requests when I need to get info about the file (file name, size, type)

Creating new objects:

    //initiate the class
    $s3 = new AmazonS3();

    $bucket = 'my_bucket';

    //upload the file           
    $response = $s3->create_object($bucket, $filename, array(
                    'fileUpload' => $filepath,
                    'acl' => AmazonS3::ACL_PUBLIC,
                    'contentType' => $file_type,
                    'storage'     => AmazonS3::STORAGE_REDUCED,
                    'headers'     => array( // raw headers
                          'Cache-Control' => 'max-age=315360000', 
                          'Expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years"))
                    )

    ));                 

    var_dump($response->isOK()); 

After a successful upload, is it possible to get the file name, size, and file type from the $response variable without making new GET requests?

Upvotes: 0

Views: 2342

Answers (2)

CyberJunkie
CyberJunkie

Reputation: 22684

I can access the returned array from $response using header

For example to get the file size

$response->header['_info']['size_upload']

Upvotes: 0

user149341
user149341

Reputation:

Those values aren't in $response, but you don't need them. You know everything you want to know already:

  • The file name is $filename.
  • The file size can be determined by filesize($filepath).
  • The file type is $file_type.

Upvotes: 1

Related Questions