Janet A
Janet A

Reputation: 11

Laravel decode base64 image and hashName and store public folder

How I can store decoded image to laravel public image path and hash image name ?

I tried like this, but didnt work and doesn't get any error message;

if (!empty($request->image)) {
    $file = base64_decode($request->image)->hashName();
    base64_decode($request->image)->store('user-uploads/avatar');
    asset('user-uploads/avatar/' . $file);
}

This code works fine but I use API and via curl sending image then needed base64 decoding:

if ($request->hasFile('image')) {
    $file = $request->file('image')->hashName();
    $request->image->store('user-uploads/avatar');
    asset('user-uploads/avatar/' . $file);
}

What you suggest save image and send image url to api and downloads image too path or send base64 image encode and in api decode, like I'm trying at the moment?

Upvotes: 0

Views: 1146

Answers (1)

atymic
atymic

Reputation: 3128

You can't call functions on the output of base64_decode, as it returns as string.

I would suggest you post the name of the file along with the base 64 encoded content, which can then be saved using laravel's storage helpers:

Storage::disk('local')->put('image.png', base64_decode($request->image))

Upvotes: 1

Related Questions