Solved

Upload BLOb File

Posted on 2009-07-14
7
1,177 Views
Last Modified: 2012-05-07
Hi Experts.

I used delphi 6 and oracle 8i, I would like upload file crd+ to web Portal and stored in table DOCUMENTS in oracle database. I created procedure AUTO_UPLOAD_MFB in oracle and used  TOraStoredProc in delphi to connect to procedure AUTO_UPLOAD_MFB.
 But I have a problem:
Access violation at address 005753F9 in module 'mfb.exe' . Read of address 00000000.
Could you please help me.

Thanks so much.
procedure AUTO_UPLOAD_MFB in oracle

(V_PARTNO IN VARCHAR2,V_PATHNAME IN VARCHAR2,V_DESC IN VARCHAR2,V_FILE_TYPE IN VARCHAR2, V_CUST_VIEW IN VARCHAR2, V_BLOB_FILE IN BLOB) 

AS

v_email_content varchar2(5000);

v_err	        varchar2(5000);

v_email_user    varchar2(100);

l_seb  CONSTANT RAW(1000) := UTL_RAW.CAST_TO_RAW('0x');
 

BEGIN

	  INSERT INTO MYSVDBA.DOCUMENTS(MIME_TYPE,NAME,BLOB_CONTENT,LAST_UPDATED,doc_size,CONTENT_TYPE,DAD_CHARSET,CONTENT) 

	  	VALUES('text/plain',V_PATHNAME,V_BLOB_FILE,SYSDATE,DBMS_LOB.GETLENGTH(V_blob_file),'BLOB','ascii',l_seb);

	  commit;
 

	  insert into mysvdba.sv_file_xref(partno, filename,file_type, cust_viewable, description, user_id, date_time, enabled, status, partno_idx)

	  	VALUES(V_PARTNO,V_PATHNAME,V_FILE_TYPE,V_CUST_VIEW,V_DESC,2454,SYSDATE,-1,'RELEASED',SUBSTR(V_PARTNO,1,10));

	  commit;

	  	  

 EXCEPTION

  WHEN OTHERS THEN

   htp.p(sqlerrm || V_PARTNO);

   v_err := sqlerrm;

   if v_err like 'ORA-01401%' then

    	insert into mysvdba.SV_FR_PART_ERROR values(V_PATHNAME,V_PARTNO,sysdate,'File name too long ' || v_err);

   	commit;

  elsif v_err like 'ORA-01691%' then

    	insert into mysvdba.SV_FR_PART_ERROR values(V_PATHNAME,V_PARTNO,sysdate,'Over size file, error in AUTO UPLOAD ' || v_err);

   	commit;

   else

    	insert into mysvdba.SV_FR_PART_ERROR values(V_PATHNAME,V_PARTNO,sysdate,'ERROR IN AUTO UPLOAD '||v_err);

   	commit;

   end if;

  RETURN;

END;
 
 
 

Code in Delphi:
 

unit UploadFilePortal;

interface

uses

   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids, ComCtrls, DBTables, IBCustomDataSet,RzLabel, ExtActns, StrUtils,

  OraClasses,

  ExtCtrls   ;

type

  TFrmUploadPortal = class(TForm)

    RzLabel1: TRzLabel;

    Label1: TLabel;

    Label2: TLabel;

    Label3: TLabel;

    Label4: TLabel;

    Label5: TLabel;

    edFilePath: TEdit;

    edFileDesc: TEdit;

    cboFileType: TComboBox;

    cboCustomerViewable: TComboBox;

    cboFileStatus: TComboBox;

    btnDialUploadPath: TButton;

    btnUploadSubmit: TButton;

    edPartNumber: TEdit;

    Label6: TLabel;

    OpenDialogGAF: TOpenDialog;
 
 

    procedure btnDialUploadPathClick(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure btnUploadSubmitClick(Sender: TObject);
 

   private

    { Private declarations }

  public

    { Public declarations }

  end;
 

var

  FrmUploadPortal: TFrmUploadPortal;
 

implementation
 

uses UnitDataConfig, Ora, gaf;
 

{$R *.dfm}
 
 

procedure TFrmUploadPortal.btnUploadSubmitClick(Sender: TObject);

var fs: TFileStream;

    bs: TBlobStream;

    PartNo: string;

    FileName,FileExt,FileName_ : string;

    MyFormatDateTime: string; //decode the datetime

    EncrypFileName: string;

    FileReleasedOnPortal:string; //use to store all file which have been released.

    i:integer;

     vBlob : TOraLob;

    OraSession : TOraSession;
 

begin
 

      FileName:= ExtractFileName(edFilePath.Text);

      FileName_ := edFilePath.Text;

      FileExt:=  ExtractFileExt(FileName);

      PartNo:= edPartNumber.Text;

      DateTimeToString(MyFormatDateTime, 'ddmmyyhhnnss', now());

      EncrypFileName:= 'F'+ MyFormatDateTime + '/' + FileName;
 

     

  with DataConfig.OraStoredProc do

  begin

       ParamByName('v_partno').AsString := PartNo;

       ParamByName('V_PATHNAME').AsString := FileName_ ; //EncrypFileName;

       ParamByName('V_DESC').AsString := edFileDesc.Text ;

       ParamByName('V_FILE_TYPE').AsString := cboFileType.Items.Strings[cboFileType.ItemIndex] ;

       ParamByName('V_CUST_VIEW').AsString := cboCustomerViewable.Items.Strings[cboCustomerViewable.itemIndex];

       ParamByName('V_BLOB_FILE').ParamType := ptInput;

       vBlob := TOraLob.Create(OraSession.OCISvcCtx);

       vBlob.CreateTemporary(ltBlob);

       vBlob.LoadFromFile(OpenDialogGAF.FileName);

       vBlob.WriteLob;

       ParamByName('V_BLOB_FILE').AsOraBlob := vBlob ;

       Execute;

  end;

       ShowMessage('File has been uploaded');

end;
 

end.

Open in new window

0
Comment
Question by:SVPIT
  • 2
7 Comments
 
LVL 36

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 24861412
i think uploading a blob via a stored proc will not work,
you'll have to use a insert statement

http://www.experts-exchange.com/Programming/Editors_IDEs/Delphi/Q_24046869.html
0
 

Author Comment

by:SVPIT
ID: 24867114
Hi Geert,

No we can upload a blob via a stored proc by using TOraStoredProc in ODAC. I added more line  Options.TemporaryLobUpdate := True;
I can upload and It's Ok now. you can view code as below:

  with OraStoredProc do
  begin
       Options.TemporaryLobUpdate := True;
       StoredProcName := 'AUTO_UPLOAD_MFB';
       Prepare;
       ParamByName('v_partno').AsString := PartNo;
       ParamByName('V_PATHNAME').AsString := EncrypFileName;
       ParamByName('V_DESC').AsString := edFileDesc.Text ;
       ParamByName('V_FILE_TYPE').AsString := cboFileType.Items.Strings[cboFileType.ItemIndex] ;
       ParamByName('V_CUST_VIEW').AsString :=    cboCustomerViewable.Items.Strings[cboCustomerViewable.itemIndex];
       ParamByName('V_STATUS').AsString := cboFileStatus.Items.Strings[cboFileStatus.itemIndex];
       ParamByName('V_BLOB_FILE').ParamType := ptInput;
       ParamByName('V_BLOB_FILE').AsOraClob.LoadFromFile(FileName);
       Execute;
       ShowMessage('File has been uploaded');
  end;

Thanks for your help.
0
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 24875265
via stored proc there is a limit of 4000 bytes
is the file bigger ?
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now