Autodesk-Forge/forge-php-client

Upload Chunk Incorrect Regex and PHPDocs

Opened this issue · 1 comments

The Upload Chunk Function in autodesk/forge-client/lib/Api/ObjectsAPI.php:1097 claims the body is SplFileObject where it's actually expecting a string.

Also there is an error with the Regex at autodesk/forge-client/lib/Api/ObjectsApi.php:1147
The forward slash between the range and size is not correctly escaped it should look like

"/^bytes [0-9]+\\-[0-9]+\\/[0-9]+$/"

I agree, I rewrote autodesk/forge-client/lib/Api/ObjectsApi.php:1147 as below

if (!preg_match("/^bytes [0-9]+-[0-9]+\/[0-9]+$/", $content_range)) {

Additionally (less of an error, more of a use case), I amended autodesk/forge-client/lib/ApiClient.php:194 from

} elseif ($method === self::$PUT) {
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
  curl_setopt($curl, CURLOPT_POSTFIELDS, file_get_contents($postData));

to

} elseif ($method === self::$PUT) {
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
  if ($endpointPath === '/oss/v2/buckets/{bucketKey}/objects/{objectName}/resumable') {
    $put = $postData;
  } else {
    $put = file_get_contents($postData);
  }
  curl_setopt($curl, CURLOPT_POSTFIELDS, $put);

Coded this way to tie into my use case of

$file = new SplFileObject($path);
...
$result = $apiInstance->uploadChunk($bucket_key, $file->getFilename(), $length, $range, $sessionId, $file->fread($length));