Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
slowbro opened this issue Nov 21, 2014 · 6 comments
Open

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

slowbro opened this issue Nov 21, 2014 · 6 comments
Labels

Comments

@slowbro
Copy link
Contributor

slowbro commented Nov 21, 2014

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) { ... }
  }
}
@ConnorVG
Copy link
Contributor

I'll look into it. It looks strange that it's there on the post data.

Sent from my iPhone

On 21 Nov 2014, at 20:53, Katelyn Schiesser [email protected] wrote:

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) { ... }
}
}

Reply to this email directly or view it on GitHub.

@adonix
Copy link

adonix commented May 26, 2017

Was this issue ☝️ ever fixed? I can't seem to upload files.

@ConnorVG
Copy link
Contributor

ConnorVG commented May 30, 2017

I couldn't replicate the issue myself.

Are you able to replicate it consistently or is a 1-off thing?

@ConnorVG ConnorVG reopened this May 30, 2017
@adonix
Copy link

adonix commented May 30, 2017

I can consistently replicated.

@ConnorVG
Copy link
Contributor

@adonix can you dump the entire stack trace of the error, please? Or the JSON response (if that's the case).

@mychalvlcek
Copy link

mychalvlcek commented Dec 22, 2020

had the same issue, you can just simply remove http_build_query from

curl_setopt($request, CURLOPT_POSTFIELDS, http_build_query($postParameters));

by custom inherited class

class CustomCurlInteractor extends CurlInteractor {

    /**
     * {@inheritdoc}
     */
    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, $postParameters);

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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants