I have an API I created in Lumen. The API allows users to upload image files to the server. The microservice works fine when I upload files directly.
The controller allows to save background and the background can be either color or image.
the API gateway works fine when I save background as a color since there is no is a file upload. background of upload working fine if it is just text fields
but if I try to save the background of the image type which uploads the image through the API gateway I get an error shown below.
since the error says unprocessable entity I am assuming the file input I not sending file data enctype='multipart/form-data' (just a guess) because it still says the field is required even though it is filled.
I am using postman to send requests
this is a part of my code that uploads images
$path = 'assets' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'backgrounds' . DIRECTORY_SEPARATOR;
$destinationPath = storage_path($path);
$background = DB::table('backgrounds')->insert([
'note_background_type' => $bg_type,
'note_background_name' => $picName,
'created_at' => \Carbon\Carbon::now()->toDateTimeString()
]);
if ($background)
{
if ($request->file('note_background_name')->move($destinationPath, $picName))
{
//
}
else
{
//
}
}
this is the method in the API gateway
public function store(Request $request)
{
return $this->successResponse($this->backgroundService->createBackground($request->all(), Response::HTTP_CREATED));
}
this is the code that sends the request to the microservice server
public function createBackground($data)
{
return $this->performRequest('POST', '/backgrounds', $data);
}
keep in mind that the API gateway works fine if I am sending data without images. the problem is when I am dealing with file uploads