Home » Developer & Programmer » Forms » Load Images from Client PC to Form (Application Server 10g R2, 10g Database)
Load Images from Client PC to Form [message #545718] Thu, 01 March 2012 21:26 Go to next message
1982Hashmi
Messages: 69
Registered: March 2011
Location: Islamabad
Member
Hi everyone,

Can someone help me that how may I load pictures from Client PC into my form (built in Forms 10g) running on Application Server.
I've already configured Webutil package.

Regards

Re: Load Images from Client PC to Form [message #545774 is a reply to message #545718] Fri, 02 March 2012 07:37 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
this is the code on WHen-Button-Pressed trigger. I could provide u a FMB file but u have do your self code i have already provide now everything is with u. We are all learner here.



CREATE TABLE images
(id NUMBER,
 images BLOB
)
/



PROCEDURE Charge_photo 
IS

  LC$Img	Varchar2(100);  
  LN$But	Number ;
  pl_id ParamList; 
  pl_name VARCHAR2(20) := 'list_params'; 
  
BEGIN
	 
	 -- Parameter list for filter --
	 pl_id := Get_Parameter_List(pl_name);
	 If NOT Id_Null(pl_id) THEN 
	 	  Destroy_Parameter_List( pl_id ) ;
	 End if ;
	 pl_id := Create_Parameter_List(pl_name); 
	 Add_Parameter(pl_id,'P_FILTRE',TEXT_PARAMETER,'*.gif,*.jpg');
	 Add_Parameter(pl_id,'P_POSY',TEXT_PARAMETER,'1');  

	 
	 -- Selected image name --
	 :global.get_file_name := '' ;

   call_form( 'get_file_name', NO_HIDE, DO_REPLACE, QUERY_ONLY, pl_id ) ;
   if not form_success Then
   	 message('pb appel get_file_name');
   end if ;
	 
	 If :GLOBAL.get_file_name is not null Then
	   -- reading the picture in the image item --
     LC$Img := :GLOBAL.get_file_name ;
     Go_block( 'IMAGES' );
     Read_Image_File(LC$Img, 'ANY', 'IMAGES.IMAGES');

     Go_item( 'IMAGES.ID' );
	 Else
	 	 Raise form_trigger_failure ;
   End if ;
  
END;


create one form and here is code of Ger_file_name

PROCEDURE GET_FICHIER IS
BEGIN
  -- Return the complete file name in the global --
  Default_Value(:CTRL.CHEMIN || '\' || :CTRL.FIC_NAME,'global.' || :PARAMETER.P_NOM_GLOBALE ); 
  -- Exit --
  Exit_Form ( NO_VALIDATE ) ;  
END;

-------------------
PROCEDURE get_list_drives IS
  LN$Lettre pls_integer := 1 ;
  LC$Drive  Varchar2(20) ;
  fic_out   TEXT_IO.FILE_TYPE ;
  fichier   Varchar2(60) ;
  LI$NumDrive pls_integer := 0 ;
BEGIN
	
	fichier := Ltrim( To_char( SYSDATE, 'YYYYDDMMHH24MISS' ) ) || '_lst_fic.txt' ;
	-- drive C: to Z: --
	For i in 2..25 loop

    LC$Drive := CHR(i+65) || ':' ;
    Begin
    fic_out := TEXT_IO.FOPEN( LC$Drive || fichier, 'W' ) ;
    If TEXT_IO.IS_OPEN( fic_out ) Then
    	-- Ok we can write on this drive --
    	If :CTRL.MAIN_DRIVE is null Then
    		 -- 1st drive with write rights --
    		 :CTRL.MAIN_DRIVE := LC$Drive ;
    	End if ;
    	
    	-- Add the drive to the list --
    	LI$NumDrive := LI$NumDrive + 1 ;
    	Add_List_Element( 'CTRL.LECTEURS', LI$NumDrive, 'Drive ' || LC$Drive, LC$Drive ) ;
    	TEXT_IO.FCLOSE( fic_out ) ;
    	-- Delete the file --
    	HOST( 'DEL ' || LC$Drive || fichier, NO_SCREEN ) ;
    End if ;
    
    Exception
      when others then
         Null ;
		End ;

  End loop ;

  -- First available drive in the list --
  If :CTRL.MAIN_DRIVE is not null Then
  	:CTRL.LECTEURS := :CTRL.MAIN_DRIVE ;
	  :CTRL.Chemin := :CTRL.LECTEURS ;
	  -- Read the directory --
	  Get_List_Rep( :CTRL.LECTEURS ) ;  	
  Else
  	-- No available drive with write right --
  	LI$NumDrive := Show_Alert('AL_ERREUR' ) ;
  	Exit_Form( NO_VALIDATE ) ;
  End if ;
  
END;
----------------
PROCEDURE get_list_rep (PC$Rep IN VARCHAR2) IS
  LN$Lettre pls_integer := 1 ;
  LC$Rep Varchar2(256) := PC$Rep ;
  LC$Filtre  Varchar2(30) ;
  fic_out TEXT_IO.FILE_TYPE ;
  fic_name Varchar2(256)  ;
  fichier  Varchar2(256)  ;  
  LI$NumDrive pls_integer := 1 ;
  LC$Cmd Varchar2(256) ;
  LC$Ligne Varchar2(256) ;
  LI$Num pls_integer := 1 ;
  LI$Pos pls_integer ;
BEGIN

    If Substr( LC$Rep, Length(LC$Rep) -2, 3 ) = '\..' And Length( LC$Rep ) > 5 Then
    	 -- Previous tree node --
    	 :CTRL.Chemin := Substr( LC$Rep, 1, Instr( LC$Rep, '\', -1, 2 ) - 1);
    	 LC$Rep := :CTRL.Chemin ;
    End if ;
    clear_list('CTRL.REPS');

    -- Target file name --
    fichier := Ltrim( To_char( SYSDATE, 'YYYYDDMMHH24MISS' ) ) || '_lst_fic.txt' ;    
    fic_name := :CTRL.MAIN_DRIVE || '\' || fichier ;
    

    -- Directory list --
    If :CTRL.FILTRE <> '*.*' Then
    	LC$Cmd := 'DIR /AD "' || LC$Rep || '\" > ' || fic_name ;        
    	Host( LC$Cmd, NO_SCREEN ) ;
    End if ;
    
    -- multi-choice Filter ? --
    If Instr( :CTRL.FILTRE, ',' ) > 0 Then
    	 LI$Pos := 1 ;
    	 Loop
    	   LC$Filtre := Split( :CTRL.FILTRE, LI$Pos ) ;
    	   Exit When LC$Filtre IS NULL ;
         LC$Cmd := 'DIR /OGN "' || LC$Rep || '\' || LC$Filtre || '" >> ' || fic_name ;        
         Host( LC$Cmd, NO_SCREEN ) ;
         LI$Pos := LI$Pos + 1 ;
    	 End loop ;
    Else
       LC$Cmd := 'DIR /OGN "' || LC$Rep || '\' || :CTRL.FILTRE || '" >> ' || fic_name ;        
       Host( LC$Cmd, NO_SCREEN ) ;	
    End if ;
    
    -- Reading the file list --
    fic_out := TEXT_IO.FOPEN( fic_name, 'R' ) ;
    If TEXT_IO.IS_OPEN( fic_out ) Then
    	Begin
    	Loop
    	   TEXT_IO.Get_Line( fic_out, LC$Ligne ) ;
    	   If LC$Ligne is not null Then
    	      If Substr( LC$Ligne, 25, 5 ) = '<DIR>' Then
    	      	-- Directory name --
    	      	If Substr( LC$Ligne, 40, 2 ) <> '.' Then
    	          LI$Num := LI$Num + 1 ;
    	          Add_List_Element( 'CTRL.REPS', LI$Num, '\' || Substr( LC$Ligne, 40, 256 ), '\' || Substr( LC$Ligne, 40, 256 ) ) ;
    	        End if ;
    	      Elsif Substr( LC$Ligne, 1, 1 ) <> ' ' Then
    	      	-- File name --
    	      	If Instr( LC$Ligne, fichier ) = 0 Then
    	      	   LI$Num := LI$Num + 1 ;
    	      	   Add_List_Element( 'CTRL.REPS', LI$Num, Substr( LC$Ligne, 40, 256 ), Substr( LC$Ligne, 40, 256 ) ) ;
    	      	End if ;
    	      End if ;
    	   End if ;
    	End loop ;
    	Exception
    		when no_data_found Then
    		  TEXT_IO.FCLOSE( fic_out ) ;
    		  HOST( 'DEL ' || fic_name, NO_SCREEN ) ;
    	End ;
    Else
    	message('Cannot read : ' || LC$Rep );
    End if ;
  
END;
-----------------------------
PROCEDURE Init_form IS
  LN$But  Pls_integer ;
  LC$Se   Varchar2(30) := Get_Application_Property( OPERATING_SYSTEM ) ;
BEGIN
	
  If :CTRL.SEP is null Then
  	Exit_Form( NO_VALIDATE ) ;
  End if ;
  
  -- Window Position --
  Set_Window_Property( 'FENETRE1', POSITION, :PARAMETER.P_POSX, :PARAMETER.P_POSY ) ;
  Clear_List('CTRL.LECTEURS');
  Clear_List('CTRL.REPS');
  
  -- Populate the filter --
  :CTRL.FILTRE := :PARAMETER.P_FILTRE ;

  
  -- Get the drive list --
  get_list_drives ;  


END;

-------------------------
FUNCTION split ( PC$Chaine IN VARCHAR2, PN$Pos IN PLS_INTEGER, PC$Sep IN VARCHAR2 DEFAULT ',' )
RETURN VARCHAR2
IS
 LC$Chaine VARCHAR2(32767) := PC$Sep || PC$Chaine ;
 LI$I  PLS_INTEGER ;
 LI$I2 PLS_INTEGER ;
BEGIN
 LI$I := INSTR( LC$Chaine, PC$Sep, 1, PN$Pos ) ;
 If LI$I > 0 Then
    LI$I2 := INSTR( LC$Chaine, PC$Sep, 1, PN$Pos + 1) ;
	IF LI$I2 = 0 Then LI$I2 := LENGTH( LC$Chaine ) + 1 ; END IF ;
	RETURN( SUBSTR( LC$Chaine, LI$I+1, LI$I2 - LI$I-1 ) ) ;
 ELSE
    RETURN NULL ;
 END IF ;
END;



Thanks




[Updated on: Fri, 02 March 2012 07:39]

Report message to a moderator

Re: Load Images from Client PC to Form [message #545776 is a reply to message #545774] Fri, 02 March 2012 07:50 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
show us Webutil package details which u have configured
Re: Load Images from Client PC to Form [message #545821 is a reply to message #545776] Fri, 02 March 2012 10:28 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member

read this first

http://www.baigzeeshan.com/2010/01/open-file-dailog-box-example-using.html
Re: Load Images from Client PC to Form [message #545826 is a reply to message #545821] Fri, 02 March 2012 10:48 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
bu using webutl

In ORACLE_HOME/forms/server/webutil.cfg file the parameter transfer.database.enabled must be set to TRUE to use this function.

- Create a table called LOBS_TABLE in SCOTT Schema
 drop table lobs_table;
 
create table lobs_table
  (blob_id number primary key,
   char_clob clob default empty_clob(),
   image_blob blob default empty_blob(),
   word_blob blob default empty_blob(),
   pdf_blob blob default empty_blob(),
   Movie_blob blob default empty_blob())
   tablespace users;

Steps to follow:

- Create a simple form on LOBS_TABLE
  Similar to this screen
  (for Word, PDF, and Movie item i am not using any special item    its just default Image item)


- To Check the progress of Uploading Files Write User-defined Trigger named "CHECK_LOB_PROGRESS" at Block level code similar to this


	
if webutil_file_transfer.Asynchronous_Upload_Success then
     message('File uploaded successfully');
     message('File uploaded successfully');
else
     message('Some error in uploading...');
     message('Some error in uploading...');
end if;

- Create WHEN-CREATE-RECORD Trigger at block level to generate Unique BLOB_IDs for Table

?
1
	
:blob_id := to_number(to_char(sysdate,'DDMMHHMISS'));

- Create 2 buttons for each Blob Item "Browse" and "View" as shown in last screen

- On Browse Photos button write this code (This will ask for File Dialog box to choose Image )

declare
    vfilename varchar2(3000);
begin
    vfilename := client_get_file_name('c:\', file_filter => ' Image files (*.jpg)|*.jpg|');
   client_image.read_image_file(vfilename,'jpg','lobs_table.image_blob');    client_image.write_image_file(vfilename,'jpg','lobs_table.image_blob',maximize_compression,ORIGINAL_DEPTH);   
end;

- On "View" button write code similar to this (To Retrieve the file which is stored in the database)
This code will copy the file from DB to Client directory C:\WINDOWS\TEMP and Open a file from there.

declare
    vboolean boolean;
    vfilename varchar2(120) := 'c:\WINDOWS\Temp\img_'||:blob_id||to_char(sysdate,'DDMMRRRR_HH24MISS')||'.jpg';
begin
  vboolean :=
  webutil_file_transfer.DB_To_Client_With_Progress
                     ( vfilename,  --filename
                       'lobs_table', ---table of Blob item
                       'image_blob',  --Blob column name
                       'blob_id = '||:blob_id, ---where clause to retrieve the record
                       'Downloading from Database', --Progress Bar title
                       'Wait to Complete'); --Progress bar subtitle
 client_host('cmd /c start '||vfilename);
end;

- Write on Browse Document button code similar to this

declare
    vfilename varchar2(3000);
    vboolean boolean;
begin
    vfilename := client_get_file_name('c:\',file_filter => 'Document files (*.doc)|*.doc|');
     
    vboolean := webutil_file_transfer.Client_To_DB_With_Progress
                     (   vfilename,
                         'lobs_table',
                         'word_blob',
                         'blob_id = '||:blob_id,
                         'Progress',
                         'Uploading File '||vfilename,
                         true,  ---Asynchronous uploading
                         'CHECK_LOB_PROGRESS'); ---User Call back trigger
                          
end;



Note: With Client_To_DB_With_Progress Procedure a progress bar will appear automatically when file is uploading to or retrieving from Database.

- Write similar code for View Document button as View Image button Only change the extension of the file at the end.

- Repeat the code same as Browse and View Document for Rest of Blobs Item (PDF and Movie)

- Run the form and Create button Press Browse button first after loading of Your file a message will appear File uploaded successfully (Not for Images, Image will appear in Image item by default)

- Save the record

- Press View to View the file stored in database.


This is i have tested my self and its working fine for me

Cheer Laughing


Re: Load Images from Client PC to Form [message #545868 is a reply to message #545774] Fri, 02 March 2012 17:42 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Laughing

[Updated on: Fri, 02 March 2012 17:43]

Report message to a moderator

Re: Load Images from Client PC to Form [message #546077 is a reply to message #545868] Mon, 05 March 2012 04:12 Go to previous message
1982Hashmi
Messages: 69
Registered: March 2011
Location: Islamabad
Member
Thank you very much.
Previous Topic: Hotel Reservation Form
Next Topic: MASTER-DETAIL FORM
Goto Forum:
  


Current Time: Fri Jul 05 23:14:22 CDT 2024