cbil360's avatar

Optimizing uploading operations in a multi location file upload application

My application has file + image upload feature in 2-3 different modules. Each module has different image size requirements.I am using blueimp uploader (https://github.com/blueimp/jQuery-File-Upload) for file uploads and it has a great PHP class which performs all image resizing and optimization.
I integrated the class in my workspace by creating a new namespace viz Acme/UploadHandler.php. I have a S3FileUploadController which uploads files to S3.Inside the S3 controller I instantiate the uplaodhandler class after a oute is called like this.

      public function uploadFile()
{
    $upload_handler = new UploadHandler();
    
}

This uploads the image to the specified location but I have to add logic for S3. I use this for standalone upload to S3

        public  function uploadS3($fileSource,$keyPath)
    { 
    $s3 = AWS::get('s3');
    $status;
    $keyPath = 'app/dir/files/';
    
    try {
            $status = $s3->putObject(array(
            'Bucket'     => env('AWS_BUCKET_NAME'),
            'Key'        => $keyPath,
            'SourceFile' => $fileSource,
            'ACL'    => 'public-read'
       ));
    } catch (Aws\Exception\S3Exception $e) {
            echo "There was an error uploading the file.\n";
    }

This works but now I dont know is it a good approach to call above method from uploadHandler class? Because the flow would be someroute->uploadFile(in S3controller)->instantiate uploadhandler->calls uploadS3(S3controller method) to upload file to S3.
Can someone suggest me if its right way to do or I am making it complicated? Suggestions to improve would help.Also I need to upload multiple images in same request.

0 likes
0 replies

Please or to participate in this conversation.