Laravel $request->getContent() returns empty string

Viewed 862

I'm posting a CSV file from one Laravel app to another:

Sending:

$contents = file_get_contents($filePath);
Log::debug('contents', ['contents'=>$contents]); // I can see contents of file
Http::withToken($token)->attach('attachment', $contents)->post($uri);

Receiving:

$content = $request->getContent();
Log::debug('about to store content to file...', ['content'=>$content]);

// about to store content to file... {"content":""}

What am I missing here?

1 Answers

Files are not the content, you should fetch the file out with.

$request->file('attachment');

If you want to send a file as a raw request body, this snippet shows you how from the documentation.

$response = Http::withBody(
    file_get_contents($filePath), 'text'
)->post($uri);
Related