Skip to main content
Question

sha1 digest when uploadin a chucked files in php

  • May 22, 2025
  • 1 reply
  • 29 views

Forum|alt.badge.img

Hello, everyone. I have been uploading large files using curl in php. Am using chunked upload documentation API.

 

<>

curl -X PUT \ https://upload.box.com/api/2.0/files/upload_sessions/F971964745A5CD0C001BBE4E58196BFD \
-H 'authorization: Bearer ACCESS_TOKEN' \
-H 'content-range: bytes 0-8388607/100000000' \
-H 'content-type: application/octet-stream' \
-H 'digest: sha=fpRyg5eVQletdZqEKaFlqwBXJzM=' \


--data-binary @/tmp/part1

>

 

I can read my file successfully in a while loop as follows

<>

if ($stream = fopen('python.exe', 'r')) {
// get contents using offset
/$data = stream_get_contents($stream, $chunkSize, $offset);
fclose($stream);
}

>

Here is my problem

 

I can get everything working but my problem is  how this message digest is being implemented.

Below is how am doing it in php

<>

$sha1= sha1_file('python.exe');

$fs =filesize($sha1);

//$sha1= sha1('python.exe');
$shs ="sha=";
$b64= base64_encode($sha1);
echo $sha1_digest=$shs.$b64;

>

Now when I pass it in the curl header , am getting error

 

<>
{"code":"invalid_digest","message":"Digest header invalid: sha=OTQ3NTgxNjNlMDRlNzc3YWVlMmI4YjRhZmYwZDNiMDY3YjIwMTQ1OA==","request_id":"4c78cabac2ecdd1a3aa0600f3b46bc52"}

>

 

1 reply

Forum|alt.badge.img

Hi , looking at this now it all looks reasonable, but my knowledge of PHP is limited. Can you confirm you are uploading in parts? If so, you need to make sure that the SHA is for the part, not the whole file.