os/slacker

Files.upload - file (image) in memory

psyciknz opened this issue · 3 comments

I'm trying to post an image to slack, that I've downloaded from a wifi camera.

So the image in is a variable ( I do this so I can control authentication if needed), but for this example, just a raw download is used:

image = requests.get(imageurl, stream=True).raw
slack.files.upload(image)

This gets a unicode error...
So I also tried:

slack.files.upload(file=image,filename="Snapshot.jpg",initial_comment=text,channels=channel)

Where I specify a name etc, but it's getting the file to be taken from the image variable rather than from disk. Is there a way I can do this?

os commented

Hi @psyciknz. It's fixed in #137. Thanks.

Thanks. So trying to work on it.
The image as being downloaded. I've tried:

image = requests.get(imageurl, stream=True).content
image = requests.get(imageurl, stream=True).raw

as input to:
slack.files.upload(content=image,title=text,channels=slack.channels.get_channel_id(channelname))

As part of the code, do you know which method I should be able to use?

My last test I used the content of the request object, and the "image" that slack shows seems to be a test representation of a binary object:

D+17S%BAD+B1BAD+B9ZBAD+9BAD+7 jBAD+3FBAD+93'zBAD+ADڲ
3UBAD+AEBAD+AABAD+80Ңm@<BAD+A2BAD+93Cި)BAD+35BAD+9qIaJBAD+1A8%zBAD+8DBAD+8zBAD+89BAD+A0BAD+A35ThRBAD+A0 M*5;BAD+15(BAD+A8AmO5BAD+89BAD+A5zBAD+A0yBAD+AYBAD+D
HJ֩    ڳBAD+93bISBAD+C:VJTBAD+15F;RAYêBAD+8C

Hmm I may have figured it out. It does seem to post an FAILED or TIMEOUT exception. But:

image = requests.get(imageurl, stream=True)
slack.files.upload(file_=image.raw,title=text,channels=slack.channels.get_channel_id(channelname))

Seems to work.