question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I add an image that is stored as binary in a BLOB column?

See original GitHub issue

Hi!

Trying to add a picture to a document that is stored as binary straight into the DB. Bot PNG and GIF files. How do I approach this problem?

document.add_picture(bin(item['data']))

item['data'] is the column that has the binary for the image.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
scannycommented, Aug 22, 2019

Wrap the image bytes in a file-like object:

import io

image_stream = io.BytesIO(bin(item["data"]))
document.add_picture(image_stream)
0reactions
rickbpscommented, Sep 20, 2022

Wrap the image bytes in a file-like object:

import io

image_stream = io.BytesIO(bin(item["data"]))
document.add_picture(image_stream)

I’ve been searching for this solution for weeks. I needed to insert a SharePoint image into a docx table and it ends up being 3 lines of code. Thanks so much.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load blobs and images into a Data Model - Microsoft Support
A Binary-typed column can store a large data size, such as an image. A large data size is known as a binary large...
Read more >
Python SQLite BLOB to Insert and Retrieve file and images
In this article, you will learn to insert and retrieve a file stored as a BLOB in the SQLite table using Python's sqlite3...
Read more >
How to store binary image (BLOB) SQL server and lo...
Create a table to contain the image as a varbinary or image. CREATE TABLE ImageAsVarBinary ( · Load an image file to the...
Read more >
User upload binary data or image to store in MySQL BLOB ...
In part 1 we have seen how to add , update and display binary data from MySQL Blob columns. Binary data like images...
Read more >
Add, update & display Unstructured binary data like ... - YouTube
Inside a MySQL Blob column binary data or unstructured data is stored. These columns are used to store images or multimedia files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found