I got response from API with JSON format have contents filename, created time, user_id, and URL. So I want to show the image from response in frontend by put the URL in <img src={props.generated} alt="image"/>
. Nothing was wrong in my frontend code, but the image was not shown.
here my image URL from response
http://localhost:8000/storage/public/user_3/1594265090.jpeg
and when I access URL, here the response in browser
The requested resource /storage/public/user_3/1594265090.jpeg was not found on this server.
Here my code
$response = $this->client->request('POST', 'API', $data);
$image = $response->getBody()->getContents();
$filePath = 'public/' . $this->getUserDir();
$fileName = time().'.jpeg';
if ($result = Storage::put($filePath . '/' . $fileName, $image)) {
$generated = $model::create([
'name' => $fileName,
'file_path' => $filePath,
'type' => 'motif',
'customer_id' => Auth::id()
]);
return response($generated);
Image put in /storage/app/public
, I'm sure it happens because the location of directory.
I'm already trying to execute command mklink /D "./storage/app/public" "./public/storage"
and I got response Cannot create a file when that file already exists.
thankyou for your suggestion in this question. It was already solved.
I'm using ln -rs ./storage/app/public ./public/storage
. But this command is Linux, so I'm using git bash
in my project directory and execute this command.
The result is solved, and I can access the image.