Dani3lSun / apex-plugin-dropzone

Oracle APEX Region Plugin - Dropzone
MIT License
72 stars 19 forks source link

Possible behavior #23

Closed jdemovic closed 7 years ago

jdemovic commented 7 years ago

Hi Daniel,

will be possible (in some next releases) to use Foreign Key(s) option in the plugin settings due to linking to a master record for file(s)?

regards

Jozef

Dani3lSun commented 7 years ago

Hi @jdemovic

atm such feature is not planned because you can use the APEX collection method. This method allows you to be as flexible as you would like to be. Just add an new DA with PL/SQL Code:

DECLARE
  -- get files data from saved apex_collection
  CURSOR l_cur_files IS
    SELECT c001    AS filename,
           c002    AS mime_type,
           d001    AS date_created,
           n001    AS file_id,
           blob001 AS file_content
      FROM apex_collections
     WHERE collection_name = 'DROPZONE_UPLOAD'; -- Default Collection Name
  --
BEGIN
  -- loop over files cursor
  FOR l_rec_files IN l_cur_files LOOP
    -- insert into own table
    INSERT INTO custom_table
      (id,
       filename,
       mime_type,
       upload_date,
       file_content,
       reference_id,
       reference_table)
    VALUES
      (custom_table_seq.nextval,
       l_rec_files.filename,
       l_rec_files.mime_type,
       l_rec_files.date_created,
       l_rec_files.file_content,
       :p1_reference_id,
       :p1_reference_table);
  END LOOP;
  -- clear original apex collection (only if exist)
  IF apex_collection.collection_exists(p_collection_name => 'DROPZONE_UPLOAD') THEN
    apex_collection.delete_collection(p_collection_name => 'DROPZONE_UPLOAD');
  END IF;
END;

Page Items to Submit: Your Items, e.g p1_reference_id,p1_reference_table

Does this help you?

jdemovic commented 7 years ago

Hi Daniel, Thanks for quick response. It's great idea. I used your plugin similar way (collection). I have one button there which grab the whole collection (user can cancel or delete files in plugin dropzone DIV till button is pressed). I was not really sure about the DA events functionality - if is it just for one uploaded file or all files.

I'll try it by Your way ASAP.

Thanks again

J

melniker commented 7 years ago

Does this help you?

I'm not the OP, but I just moved to v2.0.4 from v1.9.4 and used this method to replace my custom pl/sql code that did the insert with correct FK references. And yes, this helps me!

This works perfectly -- the DA seems to fire every time a "batch" of files selected/dragged together finishes. I was able to leave the dropzone window open and drag new files in, and the DA fired as expected each time. I also tested dragging one "good" file and one "bad" file (prohibited file extension) in. DA fired as expected.

Very helpful tip, Daniel... I suggest this gets added to the Readme - I'm happy to edit and submit PR if you'd like.

Dani3lSun commented 7 years ago

@melniker thanks, great to hear that it works as expected and people like it! :) You´re right, this should be in the readme, I can´t count the times I wrote this snipped via mail to people having questions...If you would like you can of course submit a PR