Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

upload image in s3 using byte array

Hi I want to upload image in s3, I have byte array. How i can convert byte array to a temporary url on the fly?

$byte_arr = 'iVBORw0KGgoAAAANSUhEUgAAACIAAAAhCAYAAAHL1En6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAK
T2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AU
kSYqIQkQSogh';

    //$file_content = 'data:image/jpeg;base64, $byte_arr';
    //echo "<img src='data:image/jpeg;base64, $byte_arr' />";die;
    $s3->putBucket("bucketname", S3::ACL_PUBLIC_READ);
    $fileName = 'user_1.jpg';
    //move the file
    if ($s3->putObjectFile($file, "bucketname", $fileName, S3::ACL_PUBLIC_READ)) {
        echo "We successfully uploaded your file.";
    }else{
        echo "Something went wrong while uploading your file... sorry.";
    }

so my question is how to get $file from byte array. I need tmp_url for it.

like image 984
Mayank Joshi Avatar asked May 24 '26 05:05

Mayank Joshi


1 Answers

You can use imagecreatefromstring() function:

 $data = base64_decode($byte_arr);
 $formImage = imagecreatefromstring($data);
like image 200
AkshayP Avatar answered May 26 '26 17:05

AkshayP