猿问

如何在流明中显示来自/storage/app/public 的图像?

我从 API 得到了 JSON 格式的响应,其中包含内容文件名、创建时间、user_id 和 URL。所以我想通过将 URL 放入 来显示前端响应中的图像<img src={props.generated} alt="image"/>。我的前端代码没有任何问题,但没有显示图像。

这是我的响应中的图像 URL

http://localhost:8000/storage/public/user_3/1594265090.jpeg

当我访问 URL 时,这里是浏览器中的响应

The requested resource /storage/public/user_3/1594265090.jpeg was not found on this server.

这是我的代码

      $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);

放入图像/storage/app/public,我确信它会发生,因为目录的位置。我已经在尝试执行命令mklink /D "./storage/app/public" "./public/storage"并收到响应Cannot create a file when that file already exists.


富国沪深
浏览 113回答 1
1回答

HUWWW

我正在使用ln -rs ./storage/app/public ./public/storage.&nbsp;但这个命令是Linux的,所以我git bash在我的项目目录中使用并执行这个命令。结果解决了,可以访问图片了。
随时随地看视频慕课网APP
我要回答