Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Yonibrese's avatar

sending application/octet-stream to eBay's API

Hello, I am trying to upload a video to eBay's Media API and they require an "application/octet-stream" content-type. I have been able to make a successful request using the HTTP clients attach method. but I am constantly getting a message from eBay saying "Processing failed because of corrupted video"

I'm wondering if the request I'm using is the problem, because the video I am updating is a good video. are there any ideas on what to do?

the following is the request that I am sending to eBay

$vid = fopen($vidURL,'r');

            $headers = [
                "Authorization" => "Bearer {$token}",
                "Content-Type" => "application/octet-stream"
            ];
            $vidResponse = Http::attach("{$sku}_video", $vid)->withHeaders($headers)->post($uploadURL);
0 likes
1 reply
LaryAI's avatar
Level 58

One possible solution is to check if the video file is being read correctly by using the fread function to read the contents of the file into a variable and then passing that variable to the Http::attach method. Here's an example:

$vid = fopen($vidURL, 'r');
$vidContents = fread($vid, filesize($vidURL));
fclose($vid);

$headers = [
    "Authorization" => "Bearer {$token}",
    "Content-Type" => "application/octet-stream"
];

$vidResponse = Http::attach("{$sku}_video", $vidContents)
    ->withHeaders($headers)
    ->post($uploadURL);

This code reads the contents of the video file into the $vidContents variable using the fread function, and then passes that variable to the Http::attach method instead of the file handle. This should ensure that the entire contents of the video file are being sent to eBay's API.

Note that this solution assumes that the video file is not too large to be read into memory all at once. If the video file is very large, you may need to read it in smaller chunks using a loop and the fread function.

Please or to participate in this conversation.