Argument 2 passed to Aws\AwsClient::getCommand() must be of the type array, string given php

Trying to upload a pdf to aws s3 bucket, but its showing me below error.

Error

  Argument 2 passed to Aws\AwsClient::getCommand() must be of the type array, string given 
 called in C:\xampp\htdocs\property\vendor\aws\aws-sdk-php\src\AwsClientTrait.php on line 77 
 and defined in C:\xampp\htdocs\property\vendor\aws\aws-sdk-php\src\AwsClient.php on line 209

Below is my code

1) config.php

   return[
 'S3'=>[
     'key'      =>key,
     'secret'   =>secret_key,
   'bucket'   =>bucket_name
  ]
 ];

2) start.php

   require '../vendor/autoload.php';

   use Aws\S3\S3Client;


   $config = require ('config.php');

 //create s3 instance
  $S3 = S3Client::factory([
 'version'=>'latest',
 'region' => 'us-east-1',
 'credentials' => array(
                'key'    => KEY,
                'secret' => SECRET_KEY     
 )
]);

3) upload part

  require '../fpdf/fpdf.php';
  require 'start.php';

use Aws\Exception\AwsException;

 $pdf=new FPDF();
 $pdf->AddPage();

 $pdf->SetFont('Arial','B',14);
  $txt = "Legal Document of Mr.pradeep";
$pdf->Cell(180,0,$txt,0,1,'C');
  $pdf->Line(5,20,200,20);
  $pdf->SetFont('Arial','',12);
  $content = "This is the AGREEMENT to purchase made by pradeep from XYZ on day XX/XX/XXXX,";
  $pdf->Cell(5,30,$content,0,0,'');
     $content = "is located at bangalore and his dob is XX/XX/XXXX will be owner of the plot";
  $pdf->Cell(0,45,$content,0,0,'');

    $docname  = "legaldoc.pdf";
    $filepath = "../file/{$docname}";
    $pdf->Output($filepath,'F');

try{
   $S3->putObject([
     'Bucket'     => $config['S3']['bucket'],
     'Key'    => "folder",
     'Body' => fopen($filepath,'rb'),
     'ACL' => 'public-read'
   ]);
 } catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}

This is an expanded view of the error message:

Argument 2 passed to Aws\AwsClient::getCommand() 
must be of the type array, 
string given 

called in 
  C:\xampp\htdocs\property\vendor\aws\aws-sdk-php\src\AwsClientTrait.php
  on line 77 

and defined in 
  C:\xampp\htdocs\property\vendor\aws\aws-sdk-php\src\AwsClient.php
  on line 209

Debug:

  1. Find line 77
  2. Trace back to where the argument was created as a string instead of an array.
  3. Rectify error
  4. Continue until no more errors occur…
1 Like

@John_Betong…without tracing that i would’nt have posted…its a function invoked from client side with 2nd argument takes array as an input…If u know whats the mistake point it out…Don’t simply post whats the exception msg aws as posted…

I’m confused. The error message seems clear enough to me about what the problem is. It needs an array and its getting a string instead.

As John posted

Debug:

  1. Find line 77
  2. Trace back to where the argument was created as a string instead of an array.
  3. Rectify error
  4. Continue until no more errors occur…

That’s what needs to be done. Without giving access to your server to anyone else, you are the one in the best position to look at the code.

If you don’t understand why that bit of code is assigning or returning a string instead of an array, please post that section of the code and others should be able to help.

I HIGHLY recommend using fly system to interact with remote servers and the cloud. You can use one single interface for everything. No knowledge of AWS interface is really required unless you need to debug something. If you integrate that into your project no more curl or ftp calls which is a wonderful thing. Not to mention you can swap out storage locations with minimal effort like writing to a local file system to remote / aws.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.