Solved

Upload BLOb File

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
make null the repeated levels 2 36
scroll down TListBox component in Delphi 1 30
Firemonkey Queue list 1 25
Add New Database Table in database file using delphi 3 27
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

713 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