robbiepaul / cloudconvert-laravel

A Laravel wrapper for the CloudConvert API
177 stars 34 forks source link

Conversion fails when using Laravel's file upload #9

Closed IanCaunce closed 9 years ago

IanCaunce commented 9 years ago

Hi,

When attempting to convert a file by passing the file upload object Symfony\Component\HttpFoundation\File\UploadedFile, the conversion fails with bad request.

I did some digging into it, and it seems there are multiple issues. Firstly, in the ConvertLocalFile class if its an instance of UploadedFile you run $this->setFile($file->getFilename());. This only gives the filename and not the path on disk. I believe it should be set to $this->setFile($file->getPathname());.

This still doesn't solve the issue of setting the file extension as getPathname returns a temporary path which doesn't contain the extension. I tried adding $this->setFormat($file->getClientOriginalExtension()); under where you set the filename and this seemed to solve the first issue.

However, later is still fails with 400 "Bad Request". If I visit the process url it gives back a json object including the error "File not found (Upload failed)".

I am unsure how to solve this.

The changes I made are:

function __construct($file, $converteroptions = null)
    {
        parent::__construct($file, $converteroptions);
        $this->setMethod(CloudConvert::INPUT_UPLOAD);
        $this->setFilesystem();
        if($file instanceof UploadedFile) {
            $this->setFile($file->getFilename());
            $this->setFormat($file->getClientOriginalExtension());
        }
    }