jolicode/slack-php-api

Upload files to Slack

JakeBooher opened this issue · 4 comments

Currently trying to figure out a way to upload image files using this library. I'm using 1.2.1 due to #57

I'm able to get text snippets to upload correctly, however, I cannot get a PNG image to upload.

A few variations of what I've tried:

        $image = $progressBarUtil->getImage();
        $tmp = tempnam(sys_get_temp_dir(), 'tmp');
        $fh = fopen($tmp, 'w+');
        fwrite($fh, $image);
        fclose($fh);

        $upload = $this->getBotApi()->filesUpload([
            'channels' => $channelId,
            'file' => $tmp,
            'filename' => 'image.png',
            'filetype' => 'png,
        ]);

and

        $image = $progressBarUtil->getImage();

        $upload = $this->getBotApi()->filesUpload([
            'channels' => $channelId,
            'file' => $image,
            'filename' => 'image.png',
            'filetype' => 'png',
        ]);

the $channelId variable is correctly defined, I've just excluded it here.

Everything I try I get a no_file_data error

Hi @JakeBooher thanks for letting us know!

I'm trying to debug this in #62 👍

ah, okay a bug then - thanks thought I was losing it :)

Hi @JakeBooher !

Could you try the newly released 2.3.0?
A fix has been done in Jane PHP and a example added to the tests:

public function testItCanUploadFile()
{
$client = ClientFactory::create($_SERVER['SLACK_TOKEN']);
/** @var FilesUploadPostResponse200 $response */
$response = $client->filesUpload([
'channels' => $_SERVER['SLACK_TEST_CHANNEL'],
'title' => 'Uploaded image',
'filename' => 'test-image.png',
'filetype' => 'png',
'file' => Stream::create(fopen(__DIR__.'/resources/test-image.png', 'r')),
]);
$this->assertTrue($response->getOk());
}

Thanks!

As this bug is fixed since 2.3.0 i'm closing this issue. Feel free to open a new one if file upload is still an issue. Cheers