View Full Version : updating table with two images
Vladimir Kanovnik
10-22-2003, 01:57 AM
I have table with columns id(number), photo(blob) and thumbnail(blob). I
would like to insert image (using stored procedure) from file to column
photo and in same time copy reduced image to column thumbnail. My code is:
CREATE OR REPLACE PROCEDURE "MDEMO"."PUT_PHOTO_THUMB"
(
image_file_directory in varchar2,
image_file_name in varchar2,
image_file_mime_type in varchar2,
image_http_path in varchar2,
image_http_name in varchar2,
ord_procedure_path in varchar2,
ord_content_type in varchar2,
ord_content_blob out blob
)
as
localImage ordsys.ordimage;
localThumb ordsys.ordimage;
begin
/*
* Create an empty object.
*/
localImage := ordsys.ordimage( ordsys.ordsource( empty_blob(),
null,
null,
null,
null,
null ),
null,
null,
null,
null,
null,
null,
null );
localThumb := ordsys.ordimage( ordsys.ordsource( empty_blob(),
null,
null,
null,
null,
null ),
null,
null,
null,
null,
null,
null,
null );
/*
* Process the request based on the location of the new image.
*/
if length( image_file_directory ) > 0 then
/*
* Image is stored as a FILE in a database server directory.
* Set the local image object to reference the specified file.
*/
localImage.clearLocal();
localImage.setSource( 'FILE',
image_file_directory,
image_file_name );
localImage.setMimeType( image_file_mime_type );
elsif length ( image_http_path ) > 0 then
/*
* Image is stored on a web server somewhere.
* Set the local image object to reference the URL.
*/
localImage.clearLocal();
localImage.setSource( 'HTTP',
image_http_path,
image_http_name );
else
/*
* Image is being uploaded from the client to be stored in the
database.
* Set the flag to indicate the image is to be stored in the object's
* local-data BLOB.
*/
localImage.setLocal();
localImage.setMimeType( ord_content_type );
localThumb.setMimeType( ord_content_type );
/* copy reduced image from localImage to localThumb*/
localImage.processCopy('maxScale=50,50',localThumb);
end if;
/*
* Update the image object in the table. If the image is to be stored in
* the object's local-data BLOB, then return the LOB handle so the web
* agent can store the image in the database.
*/
if localImage.isLocal() then
update MPHOTOS i set i.IMAGE = localImage where ID =
ord_procedure_path
return i.IMAGE.source.localdata into ord_content_blob;
update MPHOTOS i set i.THUMB = localThumb where ID =
ord_procedure_path
return i.THUMB.source.localdata into ord_content_blob;
else
update MPHOTOS i set i.IMAGE = localImage where ID =
ord_procedure_path;
update MPHOTOS i set i.THUMB = localThumb where ID =
ord_procedure_path;
end if;
end;
/
SHOW ERRORS;
When I want to execute (using intermedia clipboard) I receive a message
"invalid LOB locator specified". What is wrong?
Thanx in advance
--
--
,-._|\ Vladimir Kanovnik Melbourne PC UsersGroup
/ Oz \ Email: vlad@melbpc.org.au
\_,--.x/ Phone: +61 3 9791 1409
v Fax: +61 3 9791 1946
Mobile: +61 412 134012
~~ Australia ~~
Daniel Morgan
10-22-2003, 06:02 AM
Vladimir Kanovnik wrote:
I have table with columns id(number), photo(blob) and thumbnail(blob). Iwould like to insert image (using stored procedure) from file to columnphoto and in same time copy reduced image to column thumbnail. My code is:CREATE OR REPLACE PROCEDURE "MDEMO"."PUT_PHOTO_THUMB" ( image_file_directory in varchar2, image_file_name in varchar2, image_file_mime_type in varchar2, image_http_path in varchar2, image_http_name in varchar2, ord_procedure_path in varchar2, ord_content_type in varchar2, ord_content_blob out blob )as localImage ordsys.ordimage; localThumb ordsys.ordimage;begin /* * Create an empty object. */ localImage := ordsys.ordimage( ordsys.ordsource( empty_blob(), null, null, null, null, null ), null, null, null, null, null, null, null ); localThumb := ordsys.ordimage( ordsys.ordsource( empty_blob(), null, null, null, null, null ), null, null, null, null, null, null, null ); /* * Process the request based on the location of the new image. */ if length( image_file_directory ) > 0 then /* * Image is stored as a FILE in a database server directory. * Set the local image object to reference the specified file. */ localImage.clearLocal(); localImage.setSource( 'FILE', image_file_directory, image_file_name ); localImage.setMimeType( image_file_mime_type ); elsif length ( image_http_path ) > 0 then /* * Image is stored on a web server somewhere. * Set the local image object to reference the URL. */ localImage.clearLocal(); localImage.setSource( 'HTTP', image_http_path, image_http_name ); else /* * Image is being uploaded from the client to be stored in thedatabase. * Set the flag to indicate the image is to be stored in the object's * local-data BLOB. */ localImage.setLocal(); localImage.setMimeType( ord_content_type ); localThumb.setMimeType( ord_content_type ); /* copy reduced image from localImage to localThumb*/ localImage.processCopy('maxScale=50,50',localThumb); end if; /* * Update the image object in the table. If the image is to be stored in * the object's local-data BLOB, then return the LOB handle so the web * agent can store the image in the database. */ if localImage.isLocal() then update MPHOTOS i set i.IMAGE = localImage where ID =ord_procedure_path return i.IMAGE.source.localdata into ord_content_blob; update MPHOTOS i set i.THUMB = localThumb where ID =ord_procedure_path return i.THUMB.source.localdata into ord_content_blob; else update MPHOTOS i set i.IMAGE = localImage where ID =ord_procedure_path; update MPHOTOS i set i.THUMB = localThumb where ID =ord_procedure_path; end if;end;/SHOW ERRORS;When I want to execute (using intermedia clipboard) I receive a message"invalid LOB locator specified". What is wrong?Thanx in advance
I have several times in the last year posted complete code for doing
this to these usenet groups.
Go to google and find those postings. One thing I think is missing from
what you wrote is:
dbms_lob.getlength(src_file);
--
Daniel Morgan
http://www.outreach.washington.edu/ext/certificates/oad/oad_crs.asp
http://www.outreach.washington.edu/ext/certificates/aoa/aoa_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)
MyLounge.com Site Map
Forum:
Cars,
Cell Phone,
Database,
Games,
Home Improvement,
IT,
Music,
School,
Sports,
Web Design,
Web Server,
Weight Loss
The MyLounge.com forum is intended for informational use only and should not
be relied upon and is not a substitute for any advice. The information contained
on MyLounge.com are opinions and suggestions of members and is not a representation
of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for
the accuracy, completeness or usefulness of any postings or the qualifications
of any person responding. Please consult a expert or seek the services of an
attorney in your area for more accuracy on your specific situation. Please note
that our forums also serve as mirrors to Usenet newsgroups. Many posts you see
on our forums are made by newsgroup users who may not be members of MyLounge.com
Term of Service
vBulletin v3.0.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.