Uploading multiple images in larvel rest api from postman/curl are not able work. It only insert one image.
Using larvel upload form in view has no issue at all, it work fine.
<input type="file" name="image[]" multiple />
WHat i am trying is to upload multiple images with Postman and curl in Laravel rest api.
THis is controller file
public function uploadimages(Request $request){
$files = $request->allFiles('image');
$count = 0;
foreach ($files as $file) {
$file->store('public/uploads');
$count++;
//this technic also not work
/* $name= $file->getClientOriginalName();
$file->move('public/uploads', $name);
$images[]=$name;*/
}
//$count return only 1(it only upload one file)
return response()->json($count, 201);
}
This is my curl command
curl -X POST http://localhost:8000/api/uploadimages -H "Content-Type: multipart/form-data" -F "image=@/C:\xampp\htdocs\2.jpg" -F "image=@/C:\xampp\htdocs\1.jpg"
this command insert only one file.
i also put this and tried "image[]=@/C:\xampp\htdocs\1.jpg" and get the error.
curl -X POST http://localhost:8000/api/uploadimages -H "Content-Type: multipart/form-data" -F "image[]=@/C:\xampp\htdocs\2.jpg" -F "image[]=@/C:\xampp\htdocs\1.jpg"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (26) couldn't open file "/C:\xampp\htdocs\2.jpg"
In postman application also only upload one file. i double check about postman setting for uploading file from other question. i think setting is ok.
i cant find uploading multiple images in Larvel Rest api.
What is the issue there, please somebody suggest me and explain me about the issues.