Thanks for the question, sreekanth.
Asked: September 09, 2002 - 9:45 am UTC
Last updated: July 28, 2004 - 3:12 pm UTC
Version: 8.1.7.3
Viewed 1000+ times
You Asked
Tom,
I want to upload text files from webpage using utl_file. So i am doing the following
procedure copy_page is
begin
htp.p('<html>');
htp.header(3,'Upload a file');
htp.p('<body bgcolor="#CCCCCC">');
htp.formOpen(curl => 'gsi_util.copy_file', cmethod => 'POST',
cenctype => 'multipart/form-data');
htp.p('<table><tr><td>');
htp.p('File: </td><td><INPUT TYPE=file NAME="pfile">');
htp.p('</td></tr></table>');
htp.formSubmit;
htp.formClose;
htp.p('</body>');
htp.p('</html>');
end;
procedure copy_file(pFile long) is
v_filehandle utl_file.file_type;
v_filedir VARCHAR2(100) := 'f:\ORACLE\PRODDB\8.1.7\PLSQL\TEMP';
vfilename varchar2(100);
vLine long;
begin
htp.p('<html>');
htp.p('<body bgcolor="#CCCCCC">');
begin
SELECT substr(value,1,decode(instr(value,',')-1,-1,length(value),instr(value,',')-1))
into v_filedir
FROM SYS.GV_$PARAMETER
WHERE UPPER(NAME) = 'UTL_FILE_DIR';
exception
when others then
null;
end;
vFilename := 'ftptest.txt';
v_filehandle := UTL_FILE.FOPEN(v_filedir, vFilename, 'w');
UTL_FILE.PUT_LINE(v_filehandle,pfile);
UTL_FILE.FCLOSE(v_filehandle);
htp.p('upload Succesfull');
htp.p('</body>');
htp.p('</html>');
exception
when others then
htp.p('upload failed');
htp.p('</body>');
htp.p('</html>');
end;
but when it passes the pfile it is just passing the file name instead of file content. so When i create the file it is writing just the filename in it.
Please tell how to get the file content.
thanks
sreekanth.g
and Tom said...
Well, the uploaded file is stored in the database, in either a LONG RAW or a BLOB (you configure that).
If it is in LONG RAW, you won't be writing it out to the file system.
If it is in a blob, you can read out pieces of the blob using DBMS_LOB.READ, and using UTL_RAW.CAST_TO_VARCHAR2, convert the RAW binary data into varchar2 data for writing.
In any case, you need to SELECT out the blob data, iterate over it reading a chunk at a time using dbms_lob and then use utl_file.put to write it out.
It would be similar in concept to this:
</code>
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:232814159006 <code>
but instead of htp.p, you would use utl_file.put
Rating
(2 ratings)
Is this answer out of date? If it is, please let us know via a Comment