stderr33's avatar

A 'contents' key is required

I'm trying to upload an image using the LinkedIn API with this code:

protected function uploadMedia(string $uploadUrl, mixed $file_path): bool
    {
        $file = $file = Storage::disk('public')->get($file_path);

        $response = $this->httpClient
			->attach(name: 'file', contents: $file)
			->put($uploadUrl, []);

        return $response->status() == 201;
    }

but I'm getting this error: A 'contents' key is required

I've tried updating the code in different ways but still getting the same error again and again. Can anyone help ?

0 likes
1 reply
Tray2's avatar

That usually means that you need to pass a token along with the file, to make sure that it is a legit request.

1 like

Please or to participate in this conversation.