How to upload file on AWS S3 Bucket using Rest API

Posted on February 12, 2021

#Step1: Create Aws3 class which file path application/libraries/Guzzlehttp.php

Source Code:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');


use GuzzleHttp\Client;

class Guzzlehttp{

     public function __construct(){

          $this->client = new \GuzzleHttp\Client();


    public function sendMultiForm($end_point_url, $multipart){

          return $this->client->request('POST', $end_point_url, [ 'multipart' => $multipart ]);


    public function sendForm($end_point_url, $form_params){

        return $this->client->request('POST', $end_point_url, ['form_params' =>$form_params]);



#Step2: load library in Controller

class Product_Api extends CI_Controller


      public function __construct()






    public function addProductImage()



       $image_abs_path = 'uploads/products/'.$product_id.'/'.$img1_nm;



            ['name' => 'file_path_name','contents' =>$image_abs_path],

            ['name' => 'image_url', 'contents' => fopen($image_abs_path, 'r')]


     $response=$this->guzzlehttp->sendMultiForm($end_point_url, $multipart);

    // echo $body = $response->getBody();


Sign In for comment and like the post.