I am uploading a file on teamworking using the following link https://developer.teamwork.com/projects/questions/fileUpload-preferred
Here I am using PHP Codeigniter 4.x framework with CURL to send request and in response to the first step, I am getting Ref and URL both values. i.e. First step is working fine on my end.
Now for the second step as mentioned in the documentation as follows,
Send a PUT request to the link above, with the ‘file’ in the body of the request. Along with this, you need the following headers:
X-Amz-Acl: public-read, Content-Length: file-size Host:host-from-the-generate-link
I am passing file object
CodeIgniter\HTTP\Files\UploadedFile Object ( [path:protected] => /var/www/web116/tmp/phpDyYgjj [originalName:protected] => banner-01.png [name:protected] => banner-01.png [originalMimeType:protected] => image/png [error:protected] => 0 [hasMoved:protected] => [size:protected] => 639542 [pathName:SplFileInfo:private] => /var/www/web116/tmp/phpDyYgjj [fileName:SplFileInfo:private] => phpDyYgjj )
in request body.
Here is my code as follows:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // $url is value which I have gotten after first step
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Amz-Acl: public-read',
'Content-Length:' . $fileSize, // size of file
'Host: tw-bucket.s3.amazonaws.com'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['file' => $file])); // $file is file object which I have printed above
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
$result = (array) json_decode($json);
$result['http_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
But in the HTTP code, I am getting 403 rather than 200.
Can anyone please help me out with this so that I can upload the file on teamwork? I am working to upload a file for a particular task on teamwork.
Thanks