我正在使用Symfony和Buzz \ Browser供应商,我需要通过POST将文件发送到我的Slack频道。这是我应该调用的Slack方法:Slack file upload
这是我的代码:
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);
}
发布方法:
public function post($endpoint, $headers = array(), $content = '') {
$headers['Authorization'] = sprintf('Bearer %s', $this->getToken());
return $this->browser->post($this->url . $endpoint, $headers, $content);
}
我收到响应错误消息:invalid_form_data
修改
我找到了这个解决方案:How to send file data as post parameter in BuzzBrowser post call
并且工作正常,但有没有办法通过Buzz的post方法发送文件?