我正在将 Symfony 与 Buzz\Browser 供应商一起使用,我需要通过 POST 将文件发送到我的 Slack 频道。这是我应该调用的 Slack 方法:Slack 文件上传
这是我的代码:
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 方法发送文件?