简体   繁体   中英

Use of BLOB type column in Oracle APEX

I am using a table having a BLOB column used to store a user's resume (it can be a word document, a pdf file or any other binary format).

Now in Oracle Apex 4.2, when I create a form on this table, I automatically get a browse button for selecting a file for the BLOB column. I can browse through files and select a file and then I press another button (also provided automatically) to upload the file. Now if I see this record in SQL Developer or Pl/SQL developer, I see that the BLOB data is there, and I can save it to my disk or even can view it directly from database. This is all nice!

But now when I create a report on same table In Oracle APEX, and then run that report, it doesn't give me any option to view or download the binary file, instead, it only gives the text "[unsupported data type]" in the BLOB column space. I saw in Oracle APEX online documentation that When we run a report having a BLOB column APEX automatically provides a Download button.... but in actual it is not happening, and I am seeing no way of retreiving BLOB column data in Oracle APEX. Can someone please help me???

Thanks in Advance.

Storing and Accessing File Attachments in BLOB Data Types Through Oracle APEX

This solution was also performed on an Apex 4.2 release (specifically, 4.2.5); Special thanks to the Oracle Corp for hosting my test instance at: http://apex.oracle.com .

Here is the schema design for the table I used which contains a BLOB typed data column. Note: this will not be the design of the final solution; just follow with the changes as they come so that you can understand what I found out about a few limitations of the APEX Form and Report creation wizards.

First Attempt: Setting Up the APEX Table, Form and Report

Table: MY_DOC_STACK First Layout Attempt

表MY_DOC_STACK布局一

The column DOC_FILE is the BLOB type which stores the actual document attachment. This is the look of the Form and the Report created using the APEX Application wizard which points directly to the table:

ADDING a DOCUMENT to the BLOB Typed Field

如何将文档添加到BLOB列

The report query seems to work as shown below:

已确认的文档附件已添加到BLOB字段

Here is a list of more records with document attachments:

Sample Report Output With Multiple Records

具有多个记录的样本报告输出

The problem is when trying to download the file that was put into the BLOB field:

从BLOB下载文档附件

It's subtle from the picture, but the identified mime type: Application/Octet-Stream is an indicator that the APEX form has lost track of the type of file (Microsoft Word, docx) that I had just uploaded. The file saved is just a bunch of garbage characters. Trying to change the file extension doesn't help either.

Second (Revised) Attempt: Adjustments to APEX Application Design for Blob/Document Handling

Although the application regions and their components did not work immediately after the wizard completed, there are only a few minor edits to put it into working condition. Closer inspection of the form element PX_DOC_FILE shows that BLOB form elements require some additional meta-information about the file attached to the record:

<code> DOC_FILE </ code> Blob字段定义

What's missing from the blob field Form input item:

  1. Mime Type
  2. File Name
  3. Character Set
  4. BLOB Last Updated (date) Column

I went ahead and defined the additional columns and added it to the BLOB-containing table (MY_DOC_STACK), the uploading Apex form and the report region definition.

MY_DOC_STACK表修改后的布局

Note that the column names (for simplicity) have been made the same as the requirements of the Blob form element DOC_FILE .

Revised Document Attachment Apex Form

经修订的文件附件表格

I initially thought one had to be clever to anticipate all the possible values of Mime Types (msword, pdf, zip, etc.) but that was unnecessary. Likewise for the other fields reserved for character type, and last updated columns.

IMPORTANT NOTE: You can actually skip form inputs for the supporting Blob meta-data fields. Values such as MIME_TYPE and CHARACTER_TYPE are automatically detected when the document attachment is uploaded. The Apex form ITEM storing the document blob just needs the names of the columns that will store this information.

ADDITIONAL NOTE: After adding the new columns, expanding the form and report column references, you will need to clear (or truncate) the existing table or reload each document attachment to be sure. You may be able to still use the uploads from the first attempts, but you'll need to verify that for yourself to be sure.

Revised Document Blob Upload Report

修订的Blob表报告

Revised Report Output Discussion

  1. [Owner: AUDREY HEPBURN]: I forced the MIME_TYPE with my form to "Application/msword"; although the file I uploaded was ".docx" type, downloading it back through the Apex page saved it to my local client as a ".doc" format (the old MS Word format).

  2. [Owner: CHEVY CHASE]: This time, MIME_TYPE was not inputted and the Apex form process/action added this to the record when it was created:

    application/vnd.openxmlformats-officedocument.wordprocessingml.document

    This probably is the format designated by Microsoft Office 2013 . The FILE_NAME value was user defined and the .docx extension was added explicitly. The result was that downloading the file prompted the user defaulted to open up the file using the correct application on my client computer: MS Word (Version 2013).

  3. [Owner: CARRIE FISHER]: Same as test case (2) but using an Adobe PDF (Portable Document Format) Instead. Same behavior except the MIME_TYPE identified itself as application/pdf; file opened as expected.

More Discussion:

All this trouble is from the the generic DML API's that Apex uses to manage inserts, updates and deletes from the application's schema, most likely it is part of Apex's hardening against SQL injection attacks. The direct INSERT and SELECT statements used in your SQL client is not the same way that a default form design (from an application wizard) is set up to manage DML transactions.

表单处理行DML

Note that the page process: Process Row of MY_DOC_STACK looks more parameter driven. If there is a DML operation in there somewhere, it will be based first on the careful screening of each input variable submitted through the Apex form.

There are many other ways that Apex can manage DML transactions; ... this solution focuses on what was most likely encountered by the OP.

Good Luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM