phpapicloudconvert

cloundconvert api v2 in php return The tasks field is required


We are trying to update to cloudconvert api v2 as the v1 is not working anymore from january 2022.

I have been following their code and even used their online builder, which seems to work, but when testing on the server I get the following error:

enter image description here

This is how the code look which, is identical to what I got from them, except I replaced with the variables I need on the server instead of hardcoding it.

$job = (new Job())
                        ->addTask(
                            (new Task('import/raw', 'import-my-file'))
                                ->set('file', file_get_contents($f->file_current))
                                ->set('filename', $pinfo_basename)
                        )
                        ->addTask(
                            (new Task('convert', 'task-1'))
                                ->set('input_format', $f->file_current_type)
                                ->set('output_format', $f->file_convert_type)
                                ->set('engine', 'poppler')
                                ->set('input', ['import-my-file'])
                                ->set('width', 1920)
                                ->set('quality', 100)
                        )
                        ->addTask(
                            (new Task('export/s3', 'export-1'))
                                ->set('input', ["task-1"])
                                ->set('bucket', $this->amazon_s3_media[$mode]["bucket"])
                                ->set('region', $this->amazon_s3_media[$mode]["region"])
                                ->set('access_key_id', $this->amazon_s3_media[$mode]["access"])
                                ->set('secret_access_key', $this->amazon_s3_media[$mode]["secret"])
                                ->set('acl', 'private')
                                ->set('key_prefix', $f->folder_name)
                        );
                        $cloudconvert->jobs()->create($job);

I am wondering what I am doing differently to get that error and wondered if anyone is able to help me with it.


Solution

  • I found the solution. For it to not throw the error, I had to change my file_get_contens a bit, I did this by doing the following:

    $file = rtrim(file_get_contents($f->file_current, FILE_TEXT)); $file = mb_convert_encoding($file, 'UTF-8', mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true));

    and then put $file in to ->set('file', $file) instead of ->set('file', file_get_contents($f->file_current))

    So converting it from one encoding to another seemed to fix it.