我从 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.
HUWWW