How to upload file on AWS S3 Bucket using Rest API

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

Source Code:

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

include("./vendor/autoload.php");

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()

     {

         parent::__construct();

        $this->load->library('guzzlehttp');

        date_default_timezone_set('Asia/Kolkata');

     } 

    public function addProductImage()

    {  

      

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

      $end_point_url="https://www.xyz.com/";

     $multipart=[

            ['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();

    }




View More...