jeudi 4 février 2016

Base64 Image upload with Laravel and S3 resulting in blank white square with border

I have my API taking in an Base64 code from the post request but when saving it to S3 it just results in a quite square with a border about 20px square.

So everything on S3 is set up, and currently a file is saved to S3 with a file size but when I try to open it, it says its corrupt or just brings up an empty square in the browser.

Base64 Example sent:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF4AAAA0AgMAAAB+02fBAAAADFBMVEUsPk8tdKUugbcugLcemMVGAAAABHRSTlP/8//Jq4gqhAAAABpJREFUeAFjgAOpVchgwwiUGJUYlRiVGJUAANbC6gCdtA2TAAAAAElFTkSuQmCC

In a method:

$fileName = "testimage.png";
$data = $request->image;
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
$upload_success = Storage::disk('s3')->put('images/' . $fileName, $data);

Any help on getting this to successfully upload the image and possibly how I should go about getting the correct image extension?

Thanks.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1nIzhrz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire