Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3xpR-0003Se-M3 for pgsql-general@arkaria.postgresql.org; Thu, 15 Jul 2021 09:38:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3xpQ-0006xu-L0 for pgsql-general@arkaria.postgresql.org; Thu, 15 Jul 2021 09:38:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3xpQ-0006xm-B0 for pgsql-general@lists.postgresql.org; Thu, 15 Jul 2021 09:38:48 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m3xpO-0003b2-2s for pgsql-general@lists.postgresql.org; Thu, 15 Jul 2021 09:38:48 +0000 Received: by mail-ej1-x62f.google.com with SMTP id dp20so6335845ejc.7 for ; Thu, 15 Jul 2021 02:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=zHy4AAIiFSscac+w+6fUju9XvrYpxq1CapTHtpVyPGA=; b=O8s1bQTjFuFT2G1Exh+TBmhnLo+QISt4j8o+1x9O7qA2aoV6EEwCGtckewaw1zZije WNUjx1BqVYBxNPNPB9hV6sY+foWr92Q/kS9kjqPO6FBUK4XZ1n9dAmLo2paip4I9tUlp U3s2y1Y4ESVJ6B2/TrMEHbB0YZ/jCR2Kcwh//ufWQOoKqg8bhaF7VvqfXtuKPzKmBFlp 1SrH8G3XTD9iOZdfR6JEV7KR4s/B4lmEMcouG5WJD/NcHJf0r5Ju+6UJhIAtvExhDsj2 KJmmAViclwBdkBLx468fOZ84PkjkU7XMEG5Qv/osT4IjhgB16NqLGzDPQS92vMSls3n3 1H/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zHy4AAIiFSscac+w+6fUju9XvrYpxq1CapTHtpVyPGA=; b=XROvTic0APX2gZqjo3vrkxqTCSlqfxTRylbZPFifVfeAU7HlBvnKCrT4ynHBvCcvns otCMvBMUITMCKOOulD4fAfkxRhsSkQ94A2dBjBS0/F/2xzNYoXP6eOS6vn7yWgxCMAxZ QR/05SNEI+c50bvbXFvfIvOj/D1WTfE9kUvNeEmez5de65gRX8+kMbmo6kp4ZiSYXWq8 U30SEJWDme1pMMOYZh3K6e3dZYawYpbyS4NmgZz2kU6o2wmHj1hRtesQ2UlwYhcyFaKo r7VYTw53Mh6hBYGEIIlh/N/3WRItzFh2i6fnEcEPDE+msPwDDAIFtT74lwSlOvhE5GhU xAcg== X-Gm-Message-State: AOAM533u0Z7OMB0J+QLiI61RBGUSWjSp12gfaDchCH3lHYeEHIqQ3+hX uo4taRsj9ylu5G+Naos/tm5Bl0Le4GA= X-Google-Smtp-Source: ABdhPJwCeqYzTg5k1h6qFWRX4vo+YXZyDwEVImIPsNUpHqxgSozxFlYGEndcN/sE5jlfqiqgOZQmuA== X-Received: by 2002:a17:907:2067:: with SMTP id qp7mr4593748ejb.225.1626341925013; Thu, 15 Jul 2021 02:38:45 -0700 (PDT) Received: from [95.85.160.189] ([95.85.160.189]) by smtp.gmail.com with ESMTPSA id g13sm1654268ejw.15.2021.07.15.02.38.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Jul 2021 02:38:44 -0700 (PDT) Subject: Re: How to display stored image as bytea or as large objects? To: Ho John Lee Cc: PostgreSQL General References: From: Csanyi Pal Message-ID: <749d5156-d0d2-6dce-c7af-2220919395a8@gmail.com> Date: Thu, 15 Jul 2021 11:38:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: hu-HU Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Ho John Lee, I found one can in DBeaver upload an image into bytea data type column. So my issue is gone; by using DBeaver I can upload images and also display those images stored in a postgresql database. Thanks! 2021. 07. 15. 6:47 keltezéssel, Ho John Lee írta: > I use python with psycopg2, for a table 'myimage_table' with columns > 'label' and 'b' of type varchar and bytea something like this: > > > query = 'insert into myimage_table (label, b) values (%s, %s)' > imagelabel = 'some_label' > imagebuf = > b = psycopg2.Binary(imagebuf) > cur.execute(query, (imagelabel, b)) > > The SQL query doesn't have raw binary data in it, the text representing > the raw data looks something like this: \\xffd8ffe000104a... > Psycopg2 constructs the SQL query, including encoding the raw bytes into > text to send to Postgres (which converts back to raw bytes to store.) > Once you actually have raw image data in your table, you can use dbeaver > or other tools and get a rendered image corresponding to the value stored. > > --hjl > > On Wed, Jul 14, 2021 at 9:12 PM Csanyi Pal > wrote: > > 2021. 07. 14. 22:17 keltezéssel, Ho John Lee írta: > > If you have the binary data for the image in the bytea field, > DBeaver > > will display the image when you select that field in table view > of the data. > > The field will display something like "ÿØÿà  JFIF   [nnnnn]" in > the row > > (first part of data as unicode, and data length in bytes), you > won't see > > the image unless you put focus on it. > > I will try this, but do not know which SQL code will store an image > in a > bytea data type column? > > Could you give such SQL code please? > > At the moment I have stored image in an oid data type column. > > > > .--hjl > > > On Wed, Jul 14, 2021 at 12:57 PM Csanyi Pal > > >> wrote: > > > >     Hi, > > > >     I am a novice in postgresql language. > > > >     By reading the documentation about storing binary data in > postgresql > >     database, I realize that that one can store images as binary > data by > >     using bytea or BLOB data types. > > > >     I am running postgresql on Ubuntu 20.04.2 LTS and using > pgAdmin4 in > >     Desktop mode. > > > >     I have stored an image in one of my table with this command: > > > >      > >     insert into leckek > >     (az, a_tanitas_nyelve, mely_negyedevben, mely_osztalyban, > >     mely_tagozaton, mely_orakon, a_tanitas_temaja, > >        a_lecke_neve, a_lecke_gyakorlati_reszenek_neve, > >     a_lecke_gyakorlati_reszenek_dokumentuma, > >        a_lecke_elmeleti_reszenek_neve, > >     a_lecke_elmeleti_reszenek_dokumentuma, > >     a_lecke_elmeleti_reszenek_tesztje) > >     values (default, 'Hu', 1, 5, 'b', '1-2', 'Élet és mukakörnyezet', > >                      'A technika és technológia fogalma, szerepe és > >     jelentősége', > >                      'másolás', > >                      default, > >                      'A lényeg', > > > > >  lo_import('/home/pali/Irataim/Iskola/IskolaEv_2020_2021/MuszakiOraim/Digitalis_Tananyagok_Orakra/Hu/5/5_osztaly_Tananyag_01_02_orara.png'), > >                      default) > >      > > > >     so I have now in this table the first row: > >     1       "Hu"    1       5       "b"     "1-2  " "Élet és > >     mukakörnyezet" "A technika és > >     technológia fogalma, szerepe és jelentősége"    "másolás" > >         "A lényeg"      "16800" > > > >     Here the 16800 is the OID of the binary data, the image. > > > >     I would like to know how can one display this stored image > somehow by > >     using some IDE for manage databases? > > > >     In applications like pgAdmin4, Libreoffice Base, pgModeler, > DBeaver one > >     can't display this stored image. > > > >     In SQLiteBrowser (this is an IDE for SQLite databases) one > can display > >     with easy the stored image. > > > >     So is there an easy way to display a stored image in postgresql? > > > >     -- > >     Best, > >     from Paul