For development im working on windows on my laravel project. Im trying to get file uploads working locally.
My upload code:
public function addPicture(Request $request, $id)
{
$bathroom = Bathroom::withTrashed()->findOrFail($id);
$validatedData = Validator::make($request->all(), [
'afbeelding' => 'required|image|dimensions:min_width=400,min_height=400',
]);
if($validatedData->fails())
{
return Response()->json([
"success" => false,
"errors" => $validatedData->errors()
]);
}
if ($file = $request->file('afbeelding')) {
$img = Image::make($file);
$img->resize(3000, 3000, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$img->stream();
$uid = Str::uuid();
$fileName = Str::slug($bathroom->name . $uid).'.jpg';
$this->createImage($img, 3000, "high", $bathroom->id, $fileName);
$this->createImage($img, 1000, "med", $bathroom->id, $fileName);
$this->createImage($img, 700, "thumb", $bathroom->id, $fileName);
$this->createImage($img, 400, "small", $bathroom->id, $fileName);
$picture = new Picture();
$picture->url = '-';
$picture->priority = '99';
$picture->alt = Str::limit($bathroom->description,100);
$picture->margin = 0;
$picture->path = $fileName;
$picture->bathroom_id = $id;
$picture->save();
return Response()->json([
"success" => true,
"image" => asset('/storage/img/bathroom/'.$id.'/small/'.$fileName),
"id" => $picture->id
]);
}
return Response()->json([
"success" => false,
"image" => ''
]);
}
public function createImage($img, $size, $quality, $bathroomId, $fileName){
$img->resize($size, $size, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
Storage::put( $this->getUploadPath($bathroomId, $fileName, $quality), $img->stream('jpg',100));
}
public function getUploadPath($bathroom_id, $filename, $quality = 'high'){
$returnPath = asset('/storage/img/bathroom/'.$bathroom_id.'/'.$quality.'/'.$filename);
echo $returnPath;
}
I did run: php artisan storage:link
And the following path is available D:\Documents\repos\projectname\storage\app
. When I upload a file I get:
"message": "fopen(D:\Documents\repos\projectname\storage\app\): failed to open stream: No such file or directory", "exception": "ErrorException", "file": "D:\Documents\repos\projectname\vendor\league\flysystem\src\Adapter\Local.php", "line": 157,
And later on in the log:
"file": "D:\\Documents\\repos\\projectname\\app\\Http\\Controllers\\Admin\\BathroomController.php",
"line": 141, .
which points to the following line.
Storage::put( $this->getUploadPath($bathroomId, $fileName, $quality), $img->stream('jpg',100));
of the createImage function. How can I make it work on windows so that I can test my website locally?
$img->stream('jpg',100)
? – MrEduar/
from the path? – Qumber