phpibm-cloud-storage

Cannot complete file uploads with via curl and php


I have been trying to uploading files in parts to IBM storage cloud and everything seems to be okay.

IBM Documentation Link :

It involves 3 steps

Step 1: Initiate a multipart upload

I have gotten my uploadedId via Initiate a multipart upload documentation

step 2: Uploads Part

The files I uploaded was about 3504 bytes (canada1.jpg) and it was uploaded in 4 parts via Uploads Part Documentation.

Here are the successful results of uploads parts (header says HTTP/1.1 200 OK) as requested by the API response.

The file is virtually available on my IBM bucket as to whenever I query the list parts, I can get every detail of the files as per below

PartNumber: 1 
ETag: "785c3d92f3222ce11c1920c656529601" 
Size: 1024 
PartNumber: 2 
ETag: "785c3d92f3222ce11c1920c656529601" 
Size: 1024 
PartNumber: 3 
ETag: "785c3d92f3222ce11c1920c656529601" 
Size: 1024 
PartNumber: 4 
ETag: "65cb76bccd0d52ca8f2ad374694012a3" 
Size: 432 

Step 3: Complete a multipart upload

Now I tried to complete the multipart uploads following the same documentation.

Here is what it says about Complete a multipart upload which is where am having an issue

A POST request that is issued to an object with query parameter uploadId and the appropriate XML block in the body will complete a multipart upload

curl -X "POST" "https://(endpoint)/(bucket-name)/(object-key)?uploadId=(upload-id)"
 -H "Authorization: bearer (token)"
 -H "Content-Type: text/plain; charset=utf-8"
 -d "<CompleteMultipartUpload>
         <Part>
           <PartNumber>1</PartNumber>
           <ETag>(etag)</ETag>
         </Part>
         <Part>
           <PartNumber>2</PartNumber>
           <ETag>(etag)</ETag>
         </Part>
       </CompleteMultipartUpload>"

Here is my issue:

when I try to complete the file uploads as per codes below. The codes keep on loading on the browser until it times out. I have increased the timeout to 3000 severally but the same issue. It seems the post is not properly sent. can someone help me out

$url = "https://s3.us.cloud-object-storage.appdomain.cloud/mybucketname/canada1.jpg?uploadId=my-upload-id-here";

$file ='canada1.jpg';
echo $filesize = filesize($file);

$xml = '
<CompleteMultipartUpload>
<Part>
<PartNumber>1</PartNumber>
<ETag>"785c3d92f3222ce11c1920c656529601"</ETag>
</Part>
<Part><PartNumber>2</PartNumber>
<ETag>"785c3d92f3222ce11c1920c656529601"</ETag>
</Part>
<Part>
<PartNumber>3</PartNumber>
<ETag>"785c3d92f3222ce11c1920c656529601"</ETag>
</Part>
<Part>
<PartNumber>4</PartNumber>
<ETag>"65cb76bccd0d52ca8f2ad374694012a3"</ETag>
</Part>
</CompleteMultipartUpload>';


$headers = array(

"Authorization: Bearer my-access-token", 
"Host: s3.us.cloud-object-storage.appdomain.cloud",
    "Content-type: image/jpg",
    "Content-length: $filesize" ,
//"Content-length: " . strlen($xml)
);

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3000);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$data = curl_exec($ch); 
echo $data;
if(curl_errno($ch)){
    print curl_error($ch);
}
else{
    curl_close($ch);
}

Solution

  • This is really funny. Missing Post Request

    curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST');