{"id":3125,"date":"2020-08-07T11:13:41","date_gmt":"2020-08-07T10:13:41","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=3125"},"modified":"2022-02-17T07:13:47","modified_gmt":"2022-02-17T07:13:47","slug":"download-s3-file","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/platforms\/aws\/s3\/download-s3-file","title":{"rendered":"Download S3 File\/Object"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>  \/\/--------------------------------\n  \/\/----- DOWNLOAD THE S3 FILE -----\n  \/\/--------------------------------\n\n  \/\/Create temporary file destination\n  if (!is_dir($full_path_to_api . 'temp\/')) {\n      mkdir($full_path_to_api . 'temp', 0777, true);\n  }\n\n  $LocalFilename = $full_path_to_api . 'temp\/working_import.txt';\n  unlink($LocalFilename);\t\t\t\/\/Delete file destination if it already exists\n  $DownloadSuccess = false;\n  try\n  {\n    \/\/----- SETUP AWS SDK FOR S3 ACCESS -----\n    $sdk = new Aws\\Sdk(&#91;\n        'version' => 'latest',\n        'region'  => 'us-west-2',\n        'credentials' => &#91;\n            'key'    => AWS_S3_ACCESS_KEY_ID,\t\t\t\t\/\/&lt;&lt;&lt;&lt;&lt; S3 ACCESS KEY ID\n            'secret' => AWS_S3_ACCESS_SECRET_KEY,\t\t\/\/&lt;&lt;&lt;&lt;&lt; S3 SECRET ACCESS KEY\n        ],\n    ]);\n    $s3Client = $sdk->createS3();\n  \n  \n    $result = $s3Client->getObject(&#91;\n        'Bucket' => AWS_S3_BUCKET_NAME,\n        'Key'    => $S3Filename,\n        'SaveAs' => $LocalFilename\n    ]);\n    $DownloadSuccess = true;\n  }\n  catch (Exception $e)\n  {\n  }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-3125","post","type-post","status-publish","format-standard","hentry","category-s3"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/3125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=3125"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/3125\/revisions"}],"predecessor-version":[{"id":3128,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/3125\/revisions\/3128"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=3125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=3125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=3125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}