Vinh Ta
Vinh Ta

Reputation: 127

Uploading bytes using PySFTP with putfo

So I have a base64 string and wanting to decode into a file object and upload it with PySFTP. I'm getting an error:

'bytes' object has no attribute 'read'

Is my decoding wrong here?

fileObj = base64.b64decode(attach["payload"])
srv.putfo(fileObj, filename)

Upvotes: 1

Views: 1123

Answers (1)

Vinh Ta
Vinh Ta

Reputation: 127

The Connection.putfo takes a file-like object, not just "bytes":

fileObj = BytesIO(base64.b64decode(attach["payload"]))

Upvotes: 1

Related Questions