jeudi 5 avril 2018

Laravel 5.5 Storing image from base64 string

In Laravel 5.5 project, I have successfully saved the info into product table in MySQL. The info include a base64 string which is an image basically. However, I'm facing an issue while stroing the image in public folder of the laravel project. Below is my code for the ProductController.php

public function update(Request $request, $id)
{
    $data = $request->validate([
        'product_name' => 'required',
        'description' => 'required',
        'rating' => 'required'
    ]);

    $uploaded_image = $request->input('uploaded_image');
    $data['uploaded_image'] = $uploaded_image['value']; // base64 string
    $product = Product::findOrFail($id);
    $product->update($data);
    // the data stored into the database with no issue

    $image_base64 = base64_decode($uploaded_image['value']);
    $path = public_path();
    $success = file_put_contents($path, $image_base64.".png");

    return response()->json($data);
}

I see the following error below:

message:"file_put_contents(C:\xampp\htdocs\laravel-api\public): failed to open stream: Permission denied"

By seeing different sources, I did the following, but nothing changed.

  1. php artisan clear-compiled
  2. Icacls public /grant Everyone:F
  3. composer dump-autoload

Any idea?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire