我從 API 得到了 JSON 格式的響應,其中包含內容文件名、創建時間、user_id 和 URL。所以我想通過將 URL 放入 來顯示前端響應中的圖像<img src={props.generated} alt="image"/>。我的前端代碼沒有任何問題,但沒有顯示圖像。這是我的響應中的圖像 URLhttp://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.
1 回答

HUWWW
TA貢獻1874條經驗 獲得超12個贊
我正在使用ln -rs ./storage/app/public ./public/storage
. 但這個命令是Linux的,所以我git bash
在我的項目目錄中使用并執行這個命令。
結果解決了,可以訪問圖片了。
- 1 回答
- 0 關注
- 129 瀏覽
添加回答
舉報
0/150
提交
取消