Solved

Upload BLOb File

Posted on 2009-07-14
7
1,201 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 37

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 37

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Wincontrol not (correctly) drawn 15 40
Oracle encryption 12 48
how to make 2 step back? ..\..\ ExtractFilePath (paramstr(0)) 5 45
Database Design Dilemma 6 58
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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 video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

791 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