如何在流明中显示来自 /storage/app/public 的图像?
how to show image from /storage/app/public in lumen?
我收到来自 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.
谢谢你对这个问题的建议。已经解决了。
我正在使用 ln -rs ./storage/app/public ./public/storage
。但是这个命令是Linux,所以我在我的项目目录中使用git bash
并执行这个命令。
结果解决了,可以访问图片了
我收到来自 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.
谢谢你对这个问题的建议。已经解决了。
我正在使用 ln -rs ./storage/app/public ./public/storage
。但是这个命令是Linux,所以我在我的项目目录中使用git bash
并执行这个命令。
结果解决了,可以访问图片了