@ufodisko
It seems like you're trying to upload an image to an API using Laravel's HTTP Client, but encountering two different errors.
Regarding the "Maximum execution time of 60 seconds exceeded" error, it is likely that the HTTP request is taking longer than 60 seconds to complete. This could be due to various reasons, such as slow network connectivity or the API server taking too long to respond. To fix this, you can increase the maximum execution time by modifying the max_execution_time value in your php.ini file or by using the ini_set() function in your PHP code.
Regarding the "error 400: bad request" error, it indicates that the API server was not able to understand or process the request. One possible reason for this error could be that the attach() method is not properly attaching the image file to the request. Instead of using attach(), you can try using the withBody() method to create the multipart/form-data request body manually. Here's an example:
try {
$url = 'https://api.stability.ai/v1/generation/esrgan-v1-x2plus/image-to-image/upscale';
$filePath = storage_path('app/public/6iZLEJmeC6Bb_1.png');
$file = new \Symfony\Component\HttpFoundation\File\File($filePath);
$payload = [
'image' => $file,
'width' => 1024,
];
$headers = [
'Authorization' => 'Bearer ' . env('STABILITY_API_KEY'),
'Accept' => 'image/png',
];
$response = Http::withHeaders($headers)->withBody($payload, 'form-data')->post($url);
$response->throw();
} catch (RequestException $e) {
dd($e->response->status(), $e->response->body());
}
In this example, we are manually creating the multipart/form-data request body using the withBody() method and passing in an array of key-value pairs representing the form fields and their values. The image field is set to the file object created from the image file path, and the width field is set to 1024. The Authorization and Accept headers are also included. If an exception is thrown, we catch it and dump the response status and body for debugging purposes