Note that there are some explanatory texts on larger screens.

plurals
  1. POAWS PHP SDK 2 (aws.phar) does not work with Restler Framework
    primarykey
    data
    text
    <p>I have been testing some PHP scripts that uses the aws-sdk-php to upload files to S3 storage. These scripts seems to work nicely when they are executed directly from the browser, but fails when trying to use it through an API class in Luracast Restler 3.0</p> <p>A sample script that upload some dummy file is like the following:</p> <pre><code>&lt;?php require_once (dirname(__FILE__) . "/../lib/aws/aws.phar"); use Aws\Common\Aws; use Aws\S3\Enum\CannedAcl; use Aws\S3\Exception\S3Exception; use Aws\Common\Enum\Region; function test(){ // Instantiate an S3 client $s3 = Aws::factory(array( 'key' =&gt; 'key', 'secret' =&gt; 'secret', 'region' =&gt; Region::EU_WEST_1 ))-&gt;get('s3'); try { $s3-&gt;putObject(array( 'Bucket' =&gt; 'my-bucket', 'Key' =&gt; '/test/test.txt', 'Body' =&gt; 'example file uploaded from php!', 'ACL' =&gt; CannedAcl::PUBLIC_READ )); } catch (S3Exception $e) { echo "There was an error uploading the file.\n"; } } </code></pre> <p>This script is placed in the folder <strong>/util/test.php</strong>, while the aws-php-sdk is at <strong>/lib/aws/aws.phar</strong></p> <p>To test that this test method is well written I have created another php script at <strong>/test/upload.php</strong> with the following code:</p> <pre><code>&lt;?php require_once (dirname(__FILE__) . '/../util/test.php'); test(); </code></pre> <p>So I can enter in the browser <a href="http://mydomain.com/test/upload.php" rel="nofollow">http://mydomain.com/test/upload.php</a> and all is working as expected and the file is uploaded in S3 storage. </p> <p>However when I call the function test() from an API class with the Restler framework, I have an error that says that Aws cannot be found:</p> <pre><code>Fatal error: Class 'Aws\Common\Aws' not found in /var/app/current/util/test.php on line 12 </code></pre> <p>However the code is exactly the same that perfectly works when called from upload.php. I have been wasting hours trying to figure out what is happening here, but I cannot get any conclusion. Is like the aws-php-sdk autoloader does not work well under some circumstances.</p> <p>Any hints?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload