Don't use asForm(); it is replacing the body format in the Http Request which was previously set as multipart by attach():
$response = Http::attach('csv_file', $contents->post($url, $post_data);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am using the HTTP Client in Laravel 8. I am making a Curl request to an endpoint (in another framework) which expects a file from the $_FILES array, i.e:
$file = $_FILES['csv_file'];
Here is my Laravel code:
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Request;
public function index(Request $request)
{
$url = 'my-url';
$post_data = $request->post();
$contents = fopen($request->file('csv_file'), 'r');
$response = Http::attach('csv_file', $contents)
->asForm()
->post($url, $post_data);
return $response->body();
}
However after performing the Curl request, in my other application $_FILES is empty. I can see that $_POST is populated with POST data but it does not appear to be populating the file in the $_FILES array.
I have checked the value of $contents and it does contain a stream resource.
Anyone know how to do this?
Don't use asForm(); it is replacing the body format in the Http Request which was previously set as multipart by attach():
$response = Http::attach('csv_file', $contents->post($url, $post_data);
Please or to participate in this conversation.