jolicode / slack-php-api

:hash: PHP Slack Client based on the official OpenAPI specification
https://jolicode.github.io/slack-php-api/
MIT License
222 stars 56 forks source link

Upload files to Slack #58

Closed JakeBooher closed 4 years ago

JakeBooher commented 4 years ago

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

damienalexandre commented 4 years ago

Hi @JakeBooher thanks for letting us know!

I'm trying to debug this in #62 :+1:

JakeBooher commented 4 years ago

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

damienalexandre commented 4 years ago

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:

https://github.com/jolicode/slack-php-api/blob/f2c29d6392b4ddca87e21dcc782b9786f2cccb98/tests/WritingTest.php#L96-L110

Thanks!

damienalexandre commented 4 years ago

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