I actualy have the images in the IFS, and refer to them using a
"base_directory" || id || .jpg
It becomes cumbersome when there are many files and you need to control
permisions and back-ups.
I read the advice to use blobs and I decided to learn.

There are many images, and diferent users will not access the same one,
so I think it is unlikely that cache will help.


On 05/21/2015 11:06 AM, Charles Wilt wrote:
Why store them as a blob instead of simply storing a link?

As I understand it, the web server will be unable to cache the images if
they are stored as BLOBs in the DB...

Charles

On Thu, May 21, 2015 at 11:00 AM, Raul A Jager W <raul@xxxxxxxxxx> wrote:

To begin using images, I needed to learn how to upload (using the new
feature in CGIDEV2), how to store in a BLOB and how to send the BLOB to
the browser. A couple of simple programs do the job, for production you
need to include "error checking".

I created a sample table:

CREATE TABLE QGPL.FOTOS(
IDENT CHAR(10) NOT NULL,
FOTO BLOB(2m) ,
CONSTRAINT QGPL.CLAVE_PRI_FOTOS
PRIMARY KEY(IDENT)
) RCDFMT F1

A program to show a jpg in the browser:

*****************************************************************
* Sample program to show in a browser a jpg image from a BLOB *
* Autor: Raul Jager - Paraguay *
* Feel free to copy and/or include in other application *
*****************************************************************
d ident s 10
d fotito s SQLTYPE( BLOB:200000)
d fotnull s 5i 0
d datos s 1000 varying
* Fields for CGIDEV
DnbrVars s 10i 0
DsavedQueryString...
D s 32767 varying
D NewLine c x'15'
/include cgidev2/qrpglesrc,prototypeb
/include cgidev2/qrpglesrc,usec

/free
*inlr = *on; // convenient during tests
ClrHtmlBuffer();
NbrVars = ZhbGetInput(SavedQueryString:qusec);
ident = zhbGetVar('ident');

// ident is the key, no risk of sql injection for static SQL
exec sql select foto into :fotito :fotnull
from qgpl/fotos where ident = :ident;

// if the read succeds, show the image. (only jpg)
if sqlstate = '00000';
// to send other file types to the browser, you need to have
// a variable for "content type"
datos = 'Content-type: image/jpeg' +newline +newline;
WrtNoSection(%addr(datos)+2: %len(datos));
WrtNoSection(%addr(fotito_data): fotito_len);
// otherwise show the sqlstate
else;
datos = 'Content-type: text/html' +newline +newline +
'SQL dijo:' + sqlstate;
WrtNoSection(%addr(datos)+2: %len(datos));
endif;
wrtsection('*fini');

return;

Program to "upload" the images
*****************************************************************
* Sample program to upload a jpg image to a BLOB from the pc *
* Autor: Raul Jager - Paraguay *
* Feel free to copy and/or include in other application *
* when first called, it shows a form to select the pc file *
* Ok will upload the file, show it, and be ready for the next *
*****************************************************************

d ident s 10
d fotito s SQLTYPE( BLOB_file)
d datos s 1000 varying
DnbrVars s 10i 0
DsavedQueryString...
D s 32767 varying
D NewLine c x'15'
/include cgidev2/qrpglesrc,prototypeb
/include cgidev2/qrpglesrc,usec
/free
*inlr = *on;
// the "form" is in the cgidev directory, need to check error
GetHtmlIFS('/cgidev/html/get_jpg.xhtml': '<!-- _':' -->');
ClrHtmlBuffer();
NbrVars = ZhbGetInput(SavedQueryString:qusec);
ident = zhbGetVar('ident');
// no ident, just ask for the data...
if ident <> *blank;
fotito_name = zhbGetVar('imagen_tempfile');
fotito_nl = %len(%trim(fotito_name));
fotito_dl = *zero;
fotito_fo = SQFRD;
exec sql insert into qgpl/fotos
(ident, foto)
values(:ident, :fotito);
unlink(fotito_name);
endif;

// show the form every time it is called
datos = 'Content-type: text/html' +newline +newline;
WrtNoSection(%addr(datos)+2: %len(datos));

wrtsection('top');
// if some data was send show it
if ident <> *blank;
updHtmlVar('ident': ident);
updHtmlVar('state': sqlstate);
wrtsection('result');
endif;
wrtsection('pie *fini');

return;


The form from the IFS (I used /cgidev/htm directory for the sample)

<!-- _top -->
<html>
<head>
<title>Archivo</title>
</head>

<body>
<h1>Copia imagen a Tabla</h1>

<!-- multipart is needed -->
<form action="" method="post" enctype="multipart/form-data">
Identidad:<input type="text" name="ident"/><br/>
Archivo: <input type="file" name="imagen" device="files"/></br/>
<input type="submit" value="Ok"/>
</form>


<!-- _result -->
Respuesta SQL state: /%state%/<br/>
Imagen grabada:<br/>
<img src="show_jpg.asp?ident=/%ident%/" alt="imagen" />

<!-- _pie -->
</body>
</html>

-- Este e-mail fue enviado desde el Mail Server del diario ABC Color --
-- Verificado por Anti-Virus Corporativo Symantec --
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing
list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/web400.



-- Este e-mail fue enviado desde el Mail Server del diario ABC Color --
-- Verificado por Anti-Virus Corporativo Symantec --

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.