1

I'm using Symfony with Buzz\Browser vendor, I need to send file to my Slack channel via POST. This's the Slack method that I should call: Slack file upload

This's my code:

public function uploadFile(array $channels, File $file, $initial_comment = '', $title = '') {
    $channels = implode(',', $channels);
    $headers['Content-Type'] = 'multipart/form-data';
    $content = json_encode(array(
        'channels' => $channels,
        'file' => new FormUpload($file->getPathname()),
        'filename' => $file->getFilename(),
        'filetype' => $file->getExtension(),
        'initial_comment' => $initial_comment,
        'title' => $title
    ));
    return $this->post('/files.upload', $headers, $content);
}

Post method:

public function post($endpoint, $headers = array(), $content = '') {
    $headers['Authorization'] = sprintf('Bearer %s', $this->getToken());

    return $this->browser->post($this->url . $endpoint, $headers, $content);
}

I receive the response error message: invalid_form_data

EDIT:

I find this solution: How to send file data as post parameter in BuzzBrowser post call

and works fine, but is there a way to send file via Buzz's post method?

Mintendo
  • 557
  • 1
  • 8
  • 24

0 Answers0