Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload files to Slack #58

Closed
JakeBooher opened this issue Oct 11, 2019 · 4 comments
Closed

Upload files to Slack #58

JakeBooher opened this issue Oct 11, 2019 · 4 comments

Comments

@JakeBooher
Copy link

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
Copy link
Member

Hi @JakeBooher thanks for letting us know!

I'm trying to debug this in #62 👍

@JakeBooher
Copy link
Author

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

@damienalexandre
Copy link
Member

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!

@damienalexandre
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants