filestack / filestack-php

Official PHP SDK for Filestack - API and content management system that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
https://www.filestack.com
Apache License 2.0
56 stars 32 forks source link

$filelink->download($path) fails with HTTP 400 Bad Request #35

Closed schmich closed 4 years ago

schmich commented 6 years ago

I'm trying to download an image via Filelink, but it is failing with HTTP 400 Bad Request.

Simple repro:

use Filestack\Filelink;

$handle = 'XpfswLCnSx2igH7tJFbQ';
$apiKey = '...';
$filelink = new Filelink($handle, $apiKey);
$filelink->download('out.jpg');

Result:

Filestack\FilestackException with message 'Bad Request
'

The generated URL for this request is https://cdn.filestackcontent.com/XpfswLCnSx2igH7tJFbQ&dl=true, and you'll notice that visiting the link directly also results in HTTP 400.

The issue lies with the malformed URL query string &dl=true which gets added in CommonMixin::sendDownload. It should either be removed entirely or, in this case, it should be ?dl=true.

In case it matters, the Filestack Ruby library does not append &dl=true in its FilestackCommon#send_download method.

I'm happy to send a pull request to remove the query string if needed.