stephen waweru's avatar

test a file upload in postman

i am creating a method that should upload a file to an api.the method isn't uploading the file into the specific folder.and upon testing on postman i get a 200 ok status code but the file isn't uploaded on sending it at postman.this is the method in the imagecontroller

  public function pushimage(Request $request)
{			
	$file=$request->file('image');
	if($request->hasFile('image')){
		$extension = $file->getClientOriginalExtension();
		$newimage=rand() . '.' . $extension;
		$file->move(public_path() . ("/images/product/fileimage/"), $newimage);
		return response()->json($newimage);
	}else{
		return response()->json('file not found');
	}	
}

this is the api route

   Route::post('/push_image','imagecontroller@pushimage');

upon uploading the file in the body section in postman it returns the response of "file not found". i havent understood what am doing it wrong to prevent the execution of the function.

0 likes
1 reply
stephen waweru's avatar
stephen waweru
OP
Best Answer
Level 2

i had forgoten to select content-Type on my postman.upon slecting worked like a charm

Please or to participate in this conversation.