Skip to content

files.upload doesn't work with '@filename.ext' #6

Description

@slowbro

Hello,

I found a bug with files.upload. Due to the use of http_build_query() in src/Http/CurlInteractor.php, the '@' before the filename is being urlencoded, causing cURL to not attempt a file upload. I think this can be changed to remove "http_build_query", but I have a feeling that it's there for a reason.

Is there some way this cane be worked around?

    public function post($url, array $urlParameters = [], array $postParameters = [], array $headers = [])
    {
        $request = $this->prepareRequest($url, $urlParameters, $headers);

        curl_setopt($request, CURLOPT_POST, count($postParameters));
        curl_setopt($request, CURLOPT_POSTFIELDS, http_build_query($postParameters));
        # this is the edited line, that makes the request work:
        #curl_setopt($request, CURLOPT_POSTFIELDS, $postParameters);

        return $this->executeRequest($request);
    }

the request used:

        $res = $slack->execute('files.upload', [
            'file' => '@derp.jpg',
            'filename' => 'derp.jpg',
        ]);

response using code in master:

array(3) {
  ["status_code"]=>
  int(200)
  ["headers"]=>
  array(4) {
    ["Host"]=>
    string(9) "slack.com"
    ["Accept"]=>
    string(3) "*/*"
    ["Content-Length"]=>
    string(3) "154"
    ["Content-Type"]=>
    string(33) "application/x-www-form-urlencoded"
  }
  ["body"]=>
  array(2) {
    ["ok"]=>
    bool(false)
    ["error"]=>
    string(12) "no_file_data"
  }
}

expected/response with edited code:

array(3) {
  ["status_code"]=>
  int(200)
  ["headers"]=>
  array(5) {
    ["Host"]=>
    string(9) "slack.com"
    ["Accept"]=>
    string(3) "*/*"
    ["Content-Length"]=>
    string(5) "66013"
    ["Expect"]=>
    string(12) "100-continue"
    ["Content-Type"]=>
    string(70) "multipart/form-data; boundary=----------------------------d5bae95ca2b5"
  }
  ["body"]=>
  array(2) {
    ["ok"]=>
    bool(true)
    ["file"]=>
    array(35) { ... }
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions