Translations of this page:

How can i load multiple files in the forum

With the forum_apis package, it is now possible for those who wants to use the forum as a documents library to load their files automatically into the forum.

How is that possible?

In fact this is very easy to do that with pl/sql and the forum_api package.

The first thing you need is to create a directory on the oracle server that will be used by the following procedure to read the files.

Once you have grand read privilege on this new directory (call BLOBDIR in my example), you just have to create this small procedure.

Loader

CREATE OR REPLACE PROCEDURE upload_file(p_filename VARCHAR2,
                                      p_forum_id INTEGER) IS
  v_item   INTEGER;
  v_blob   BLOB;
  v_bfile  BFILE;
  v_fileid INTEGER;
BEGIN
  forum_api.item_add(p_forum_id => p_forum_id,
                     p_title    => p_filename,
                     p_desc     => p_filename,
                     p_text     => p_filename,
                     p_closed   => 1,
                     p_item_id  => v_item);
  INSERT INTO t_forum_uploaded_items
  VALUES
    (t_uploaded_items_seq.NEXTVAL,
     empty_blob(),
     'application/msword',
     p_filename,
     0,
     NULL)
  RETURNING file_id, file_up INTO v_fileid, v_blob;
  v_bfile := bfilename(directory => 'BLOBDIR', filename => p_filename);
  dbms_lob.fileopen(v_bfile);
  dbms_lob.loadfromfile(v_blob, v_bfile, dbms_lob.getlength(v_bfile));
  dbms_lob.fileclose(v_bfile);
  UPDATE t_items SET as_file = 1 WHERE item_id = v_item;
  COMMIT;
  INSERT INTO t_items_up_items VALUES (v_item, v_fileid);
  COMMIT;
END;

This procedure will do the following thing

  • Take a forum id and a filename as parameters
  • Create a new topic on the selected forum with a topic that will get its title, description, and text set to the filename.
  • It close the topic (but you can change it)
  • It read the file, upload it to the forum table and make the link between the topic and this file.

How to use it?

To use it you will have to do the following as the forum_app user

Sample

-- For 0.7.0 users
begin
forum_context.set_context('<YOUR FORUM LOGIN>','<YOUR FORUM PASSWORD>');
upload_file(1,'toto.txt');
ctx_ddl.sync_index('topic_titre_idx');
ctx_ddl.sync_index('topic_texte_idx');
ctx_ddl.sync_index('topic_file_idx');
end;
/
 
-- For previous versions
begin
wwctx_api.set_context('<YOUR FORUM LOGIN>','<YOUR FORUM PASSWORD>');
upload_file(1,'toto.txt');
ctx_ddl.sync_index('topic_titre_idx');
ctx_ddl.sync_index('topic_texte_idx');
ctx_ddl.sync_index('topic_file_idx');
end;
/

 
forum/faq/load_files.txt · Last modified: 2009/08/21 16:09 by helyos
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported