How to upload binary file in database?
Using servlets..how to upload binary file into database...
How to get the data of file in servlet...
Please reply...i'm unable to find exact code...that i want..
You need to do two separate parts: accept the file from a HTTP multi-part POST and then stream it into a BLOB on the database. To do the former, download Jakarta Commons FileUpload. There is extensive documentation on how to write a simple handler for the upload. You then need to send the data to a BLOB. The specifics vary from database to database but generally you will insert or update a row with an empty blob, get a reference to the blob, pipe the data and then commit.
If you do a quick forum search, this question has been asked (and answered) dozens of times. Some of the replies may even have code for you. Best of luck.
- Saish
Similar Messages
-
How to upload a file to database in Apex 4.2.2?
How to upload a file to database in Apex 4.2.2 in Existing Application? Also How to view the uploaded file within this application?
Any help to his question is very appreciated?
Thanks,
Prak.980835 wrote:
Please update your forum profile with a real handle instead of "980835".
Actually we want to upload the file to our own table and retrive from it as well. Is it possible to see the file of person whom we are pulling?
This is covered in the documentation: About BLOB Support in Forms and Reports. There's also a tutorial in the Oracle Learning Library. -
How can upload doc file into database !!
Dear Everyone,
How can i upload a doc file into Mysql database ....
can any one please give ur suggestions...
i will show u my code
upload.jsp
<form name="uploader" action="uploaded.jsp"
enctype="multipart/form-data">
<div align="center">
<table id="table1" border="1" bordercolor="#ff0000"
cellpadding="0" cellspacing="0" width="50%">
<tbody bgcolor="#c8d8f8">
<tr>
<td bgcolor="#ccccff">
<p align="center">
Resume Upload! </p>
</td>
</tr>
<tr>
<td>
<p align="center">You can upload your
resume.. </p>
<p align="center">
<table align="center" border="1"
cellpadding="10" cellspacing="10">
<tbody>
<tr>
<td>
<p><input name="file" type="file">
<input name="uploadButton" value="Upload"
type="submit"></p>
</td>
</tr>
</tbody>
</table>
</p>
</td>
</tr>
</tbody>
</table>
</div>
</form>
uploaded.jsp
<BODY>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%
String file1=request.getParameter("file");
int len;
String query;
PreparedStatement pstmt;
int i=0;
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection("jdbc:mysql://localhost:3306 Connection conn= /employee","root","");
try {
File file = new File(file1);
if (file==null)
%>
<center>Nothing in It</center>
<%
else
FileInputStream fis = new FileInputStream(file);
len = (int)file.length();
query = ("insert into loader(resume) VALUES(?)");
pstmt = conn.prepareStatement(query);
pstmt.setString(1,file.getName());
pstmt.setInt(2, len);
//method to insert a stream of bytes
pstmt.setBinaryStream(3, fis, len);
i=pstmt.executeUpdate();
if(pstmt!=null)
pstmt.close();
if(conn!=null)
conn.close();
} catch (Exception e) {
e.printStackTrace();
if(i>0)
out.println("uploaded");
else
out.println("not uploaded")
%>
</BODY>File file = new File("myDoc.doc");
FileInputStream fis = new FileInputStream(file);The file name will most likely NOT be hard-coded. I don't think the question surrounding this topic is how to do the insert statement (he/she clearly knows SQL).
HTTP and the web browser take care of the file transfer, but the server stores the file in a temporary location. The question is, "How do I found out that location?" In PHP (I know that doesn't offer much help to you, but ...), that location is held in a variable called $_FILES. From there you can simply copy the file to a location you specify (probably with a user-specified name under a directory specifically for that user).
I hope this is of some help:
http://www.oop-reserch.com/mime_example_4.html
Good Luck,
C. R. -
How to upload pdf file to DataBase using webdynpro abap.
Hi Experts,
how can i upload a pdf file in document server using webdynpro abap and display the same pdf file on the view using webdynpro abap.
Please Provide requried information .
Thanks & Regards.
Bhushan.NB - the "data" that is returned by these classes is the data as defined in an adobe form - it doesn't return the content of non-form PDF documents.
The PDF must be an interactive form ( although that doesn't restrict you to using the SAP process for creating the form is my understanding - but I could be wrong. )
Edit - I was wrong! ONLY PDF documents that have been created by the ADS can have data extracted using these classes. So unless you are using Adobe interactive forms - then you will get no value from this functionality - and if you're using AIF then you're probably just use the standard UI element
Edited by: Chris Paine on Oct 26, 2010 6:04 PM -
How to batch upload PDF files into database BLOB
Hello.
I have a requirement to batch upload PDF files into BLOB column of an Oracle 8.1.7 table from Forms 6i Web. The content of the blob column (ie. the PDF content) MUST be displayable from all client software (eg. Oracle Web forms, HTML forms, etc.)
Our environment is
Middle-tier is 9iAS on Windows/2000
Database is Oracle 8.1.7.0.0 on VMS
Oracle Web Forms 6i Patch 10
Basically my Oracle web form program will display a list of PDF files to upload and then the user can click on the <Upload> button to do the batch upload. I have experimented the following approaches but with no luck.
1. READ_IMAGE_FILE forms built-in = does NOT work because it cannot read PDF file. I got error FRM-47100: Cannot read image file
2. OCX and OLE form item = cannot use this because it does NOT work on the Web. I got error FRM-41344 OLE object not defined
3. I cannot use DBMS_LOB to do the load because the PDF files are not in the database machine.
4. Metalink Note 1682771.1 (How to upload binary documents back to database blob column from forms). When I used this, I got ORA-6502 during the hextoraw conversion. In using this solution, I have downloaded a bin2hex.exe from the Google site. I've noticed that when I looked at the converted HEX file, each line has the character : (colon) at the beginning of each line. I know the PDF file has been converted correctly to HEX format because when I convert the HEX file back to BIN format using hex2bin.exe, I'm able to display the converted bin file in Acrobat Reader. When I removed the : (colon) in the HEX file, I did NOT get the ORA-6502 error but I CANNOT display the file in Acrobat Reader. It gives an error "corrupted file".
5. upload facility in PL/SQL Web toolkit - I tried to automatically submit the html form (with htp.p) but it does NOT load the contents of the file. I called the URL from Oracle forms using web.show_document. There seems to be issues with Oracle Web forms (JInitiator) and HTML (+ htp.p).
The other options I can think of at this point are:
1. Use SQL*Loader to do the batch upload via SQL*Net connection and use HOST() built-in from Oracle Webforms to execute SQL*Loader from the 9iAS.
2. Write a Visual Basic program that reads a binary file and output the contents of the file into a byte array. Then build a DLL that can be called from Oracle webforms 6i via ORA_FFI. I don't prefer this because it means the solution will only work for Windows.
3. Write a JSP program that streams the PDF file and insert the contents of the PDF file into blob column via JDBC. Call JSP from forms using web.show_document. With this I have to do another connection to the database when I load the file.
4. Maybe I can use dbms_lob by using network file system (NFS) between the application server and VMS. But this will be network resource hungry as far as I know because the network connection has to be kept open.
Please advise. Thank you.
Regards,
ArmandoI have downloaded a bin2hex.exe from the Google site.
... each line has the character : (colon) at the
beginning of each line. I'm afraid it isn't a correct utility. I hope you'll find the source code of a correct one at metalink forum:
Doc ID: 368771.996
Type: Forum
Subject: Uploading Binary Files: bin2hex and hex2bin do not reproduce the same file
There is some links to metalink notes and some example about working with BLOB at http://www.tigralen.spb.ru/oracle/blob/index.htm. Maybe it helps. Sorry for my English. If there is any problem with code provided there, let me know by e-mail. -
How to upload any file type to R/3
Please explain step by step how to upload any file type to R/3
Thanks in advanceHi
There are many ways of uploading any file type to R3, provided it depends on how do you want to store it.
In general there are two easy ways, one is using the upload UI element, you can specify a path in the server and have configured it for all files and store the file directly in the file directory of the server.
Secondly, you need to do some work on the sap side, like creating a simple rfc, which will take up the file content as a 'binary' (raw) data type and store in the database with the relevant parameters. you rfc will take / get the update from the webdynpro UI element ( you need to do create a model ..context / binding..etc ). The whole file will be stored in binary form.
Hope this gives you some picture of how to go about on it.
if you have any specific questions do let us know
thanks -
How to save pdf file in database
Dear All,
my application is forms 6i and database is 8i,requirement is that how to save pdf file in database and users can view through formsI'll apologize up front for the length of this post. I have a few database procedures I created that write a file to a BLOB column in a table as well as retrieve the BLOB from the column after it stored there. I have successfully stored many different types of binary file to the database using these procedures - including PDF files. I have not used these procedures in a Form so I can confirm that they will work, but theoretically they should work. I'm including the code for each procedure in this posting - hence the apology for the long post! :-)
Also, since these procedures reside on the database you will need to use Forms TEXT_IO built-in package to write your file to the server before you can use these procedures to store and retrieve the file from the database.
These procedures reads and writes a binary file to a table called "LOB_TABLE." You will need to modify the procedure to write to your table.
-- Author : Craig J. Butts (CJB)
-- Name : load_file_to_blob.sql
-- : This procedure uses an Oracle Directory called "IN_FILE_LOC". If you
-- already have a directory defined in the database or would prefer to use
-- a different Directory name, make sure you modify line 21 to reflect the
-- new Directory name.
-- ==================================================================================
-- History
-- DATE WHO DESCRIPTION
-- 12/11/07 CJB Created.
CREATE OR REPLACE PROCEDURE load_file_to_blob (p_filename IN VARCHAR2) IS
out_blob BLOB;
in_file BFILE;
blob_length INTEGER;
vErrMsg VARCHAR2(2000);
BEGIN
-- set the in_file
in_file := BFILENAME('IN_FILE_LOC',p_filename);
-- Get the size of the file
dbms_lob.fileopen(in_file, dbms_lob.file_readonly);
blob_length := dbms_lob.getlength(in_file);
dbms_lob.fileclose(in_file);
-- Insert a new Record into the tabel containing the
-- filename specified in P_FILENAME and a LOB_LOCATOR.
-- Return the LOB_LOCATOR and assign it to out_blob.
INSERT INTO lob_table (filename, blobdata)
VALUES (p_filename, EMPTY_BLOB())
RETURNING blobdata INTO out_blob;
-- Load the file into the database as a blob.
dbms_lob.open(in_file, dbms_lob.lob_readonly);
dbms_lob.open(out_blob, dbms_lob.lob_readwrite);
dbms_lob.loadfromfile(out_blob, in_file, blob_length);
-- Close handles to blob and file
dbms_lob.close(out_blob);
dbms_lob.close(in_file);
commit;
-- Confirm insert by querying the database
-- for Lob Length information and output results
blob_length := 0;
BEGIN
SELECT dbms_lob.getlength(blobdata) into blob_length
FROM lob_table
WHERE filename = p_filename;
EXCEPTION WHEN OTHERS THEN
vErrMsg := 'No data Found';
END;
vErrMsg := 'Successfully inserted BLOB '''||p_filename||''' of size '||blob_length||' bytes.';
dbms_output.put_line(vErrMsg);
END;
-- Author : Craig J. Butts (CJB)
-- Name : write_blob_to_file.sql
-- Descrip : This procedure takes a BLOB object from a database table and writes it
-- to the file system
-- ==================================================================================
-- History
-- DATE WHO DESCRIPTION
-- 12/11/07 CJB Created.
CREATE OR REPLACE PROCEDURE write_blob_to_file ( p_filename IN VARCHAR2 ) IS
v_blob BLOB;
blob_length INTEGER;
out_file UTL_FILE.FILE_TYPE;
v_buffer RAW(32767);
chunk_size BINARY_INTEGER := 32767;
blob_position INTEGER := 1;
vErrMsg VARCHAR2(2000);
BEGIN
-- Retrieve the BLOB for reading
BEGIN
SELECT blobdata
INTO v_blob
FROM lob_table
WHERE filename = p_filename;
EXCEPTION WHEN OTHERS THEN
vErrMsg := 'No data found';
END;
-- Retrieve the SIZE of the BLOB
blob_length := DBMS_LOB.GETLENGTH(v_blob);
-- Open a handle to the location where you are going to write the blob
-- Note: The 'WB' parameter means "Write in Byte Mode" and is only
-- available in the UTL_FILE pkg with Oracle 10g or later.
-- USE 'W' instead for pre Oracle 10q databases.
out_file := UTL_FILE.FOPEN('OUT_FILE_LOC',p_filename, 'wb', chunk_size);
-- Write the BLOB to the file in chunks
WHILE blob_position <= blob_length LOOP
IF ( ( blob_position + chunk_size - 1 ) > blob_length ) THEN
chunk_size := blob_length - blob_position + 1;
END IF;
dbms_lob.read(v_blob, chunk_size, blob_position, v_buffer );
UTL_FILE.put_raw ( out_file, v_buffer, TRUE);
blob_position := blob_position + chunk_size;
END LOOP;
END;Hope this helps.
Craig...
-- If my response or the response of another is helpful or answers your question please mark the response accordingly. Thanks! -
How to upload a file in servlet ?
hi i am new to this concept ..............
i need upload a file in mysql database .........
i created a form ...
<html>
<form method="post" action="http://localhost:8080/examples/servlet/UploadFile" enctype="multipart/form-data">
File
<input type="file" name="upload"/>
<input type="submit" value="load" />
</form>
</html>
what servlet receives from request ? how it will be stored in database ...
i need a detail explanation ...
ThanksThe apache jakarta commons FileUpload project has sample code for how to upload a file.
To store the file in the database you would use a preparedStatement. You can use anyone of the following methods ; setBlob, setBinaryStream, setBytes.
The datatype of the column storing the document depend on the databse. SQL Server used image and postgres uses bytea -
i would like to know how to upload a file (image, text, exe, etc.) to a database. i have trying a sample code in a book called Java Servlet Programming by Jason Hunter & William Crawford, published by O'Reilly....i have problem when compile that source code.
Thank you very muchi can compile that code already...all the uploaded files are to a folder in my c:.....now i need to know how to write a code to store those uploaded files to a database (MS Access)..
TQ -
How to upload pdf file format in unix file directory?
how to upload pdf file format in unix file directory?
Hi Karthikeyan,
If you have PDF internal table with you, You can follow the below method to upload into Unix directory.
DATA:file_path TYPE char100 VALUE '/usr/sap/tmp/rep_out.PDF'.
OPEN DATASET file_path FOR OUTPUT IN BINARY MODE.
IF sy-subrc EQ 0.
LOOP AT it_pdf.
TRANSFER it_pdf TO file_path.
ENDLOOP.
ENDIF.
CLOSE DATASET file_path.
Thanks
Venkat.O -
How to upload a file into server using j2ee jsp and servlet with bean?
How to upload a file into server using j2ee jsp and servlet with bean? Please give me the reference or url about how to do that. If related to struts is more suitable.
Anyone help me please!u don't need j2ee and struts to do file uploading. An example is as such
in JSP. u use the <input> file tag like
<input type="file"....>You need a bean to capture the file contents like
class FileUploadObj {
private FormFile srcFile;
private byte[] fileContent;
// all the getter and setter methods
}Then in the servlet, you process the file for uploading
* The following loads the uploaded binary data into a byte Array.
FileUploadObj form = new FileUploadObj();
byte[] byteArr = null;
if (form.signFile != null) {
int filesize = form.srcFile.getFileSize();
byteArr = new byte[filesize];
ByteArrayInputStream bytein = new ByteArrayInputStream (form.srcFile.getFileData());
bytein.read(byteArr);
bytein.close();
form.setFileContent(byteArr);
// Write file content using Writer class into the destination file in the server.
... -
Upload .txt file to database in coldfusion
Hi i need to know how to upload text file in to database using coldfusion and the file does not have any column names. Can anyone help me in this.
The sample of data in file is:
00012009032216001111039289000005.9900100000000000000.00You can start by using list functions. After uploading and reading the file, you can treat the resulting variable as a list delimited by chr(10) & chr(13). As far as processing each line goes, you have to know it's structure.
-
How to upload image files in sqlserver from jsp
hi friends,
i want to upload images to sqlserver how will i store url of the image or dorectly store the file in binary format, if we store in related path,plese give some ideas on store that paths in data base and how we store that image files in user directories.
byehi jay , I know that concept , but i dont know how to upload image files to server Please help me
here i am giving my problem
If any user register with site, he has the option to upload his image to the site, so i am using in html file upload option, But i dont know how to store that iamge into the server
please give me suggestion
regards
sudhakar -
How to upload Excel file in BI using function module in abap program
How to upload Excel file in BI using function module in abap program?
Hi Anuj,
To upload the file , you can try a standard program "RSEPSFTP" .
while you execute the program , a selection screen appears in which the inputs should be give as
RFC destination - The target server name
FTP command- PUT
local file - your file name
local directory - path of your local file
remote file - your target file name
remote directory - where it has to be stored
Hope this is useful for you
Thanks & regards
Anju -
How to upload pdf file in a canvas in flex web application?
how to upload pdf file in a canvas in flex web application?
Hey saif.antri,
You can view PDFs and more using iBooks on your iPhone:
iBooks: Viewing, syncing, saving, and printing PDFs on iPhone, iPad, and iPod touch
http://support.apple.com/kb/HT4227
Have a great day,
Delgadoh
Maybe you are looking for
-
Please help me to get the HP G60-508 Drivers For XP. Specially for sound card.
-
How to prevent from creating multiple deliveries per sales order
Hi, Appreciate your help on the below., I do not want the users to create multiple deliveries for a single sales order. They should only be allowed to create one delivery and it can either be a full delivery or a partial delivery. Is there any possib
-
How to addRecord in Web Dynpro to Model node (Entity Service ref)
Hi, 1) I create Entity Service in CAF and try to write web dynpro Table UI for it. 2) is it possible with using Model Node? or I MUST use Value Node - Table must have possibilities for Add, Edit and Delete records. Now I can edit, and delete records,
-
Hello... I am a PI consultant who inherited MDM recently. MDM 5.5, SP06 My issue is that I have an existing map that works fine, but the source schema is changing to add a few new fields. I need to map the new fields to my existing catalog repositor
-
Hi everyone, i gte the next while making a request to the server: java.lang.IllegalStateException: No Factories configured for this Application - typically this is because a context listener is not setup in your web.xml. A typical config looks like t