Upload de arquivos?

Perguntas relacionadas a questões técnicas do Oracle EBS. Criação de Concorrentes, Value Sets, Alerts, Forms Personalizations, Configurações, etc
Responder
ricardorauber
Rank: Analista Júnior
Rank: Analista Júnior
Mensagens: 96
Registrado em: Qua, 21 Jun 2006 11:33 pm
Localização: Canoas RS

Pessoal,

Estou com um problema, preciso fazer upload de arquivos em uma customização do EBS, mas infelizmente não tem como usar o Forms para fazer isso. Dentro do módulo PO, na Ordem de Compra, tem um processo nativo que faz uploads mas funciona em PL/WEB (Package UTP) e eu não consegui de maneira alguma fazer funcionar, acredito que falte algum parâmetro.

Alguém já fez algo parecido ou tem alguma idéia que possa me ajudar?

Valeu!
ricardorauber
Rank: Analista Júnior
Rank: Analista Júnior
Mensagens: 96
Registrado em: Qua, 21 Jun 2006 11:33 pm
Localização: Canoas RS

Eu consegui usar o processo nativo que carrega na tabela FND_LOBS, ficou muito bom!

Selecionar tudo

DECLARE
	
	access_id     NUMBER;
  l_server_url  VARCHAR2(255);
  l_parameters  VARCHAR2(255);
  button_choice NUMBER;
  l_file_id     VARCHAR2(256);
  l_gfm_id      NUMBER := NULL;
  v_erro        VARCHAR2(4000);
  
BEGIN
	
	-- Cria o acces_id
  access_id := fnd_gfm.authorize(NULL);
  
  -- Busca o endereço do agente web
  fnd_profile.get('APPS_WEB_AGENT',l_server_url);
  
  -- Monta os parâmetros
  l_parameters := 'access_id=' || access_id || ' l_server_url=' || l_server_url;
  
  -- Chama a página que faz upload
  fnd_function.EXECUTE(function_name => 'FND_FNDFLUPL',
                       open_flag     => 'Y',
                       session_flag  => 'Y',
                       other_params  => l_parameters);
                       
  -- Pergunta se deu certo o upload
  fnd_message.set_name('FND','ATCHMT-FILE-UPLOAD-COMPLETE');
  button_choice := fnd_message.question(button1     => 'YES',
                                        button2     => NULL,
                                        button3     => 'NO',
                                        default_btn => 1,
                                        cancel_btn  => 3,
                                        icon        => 'question');

  -- Prepara a variável ID interna
  l_file_id := '';
  copy(l_file_id,'document_header.file_name_display');
  
  -- Busca o ID que foi gravado na tabela FND_LOB.FILE_ID
  l_gfm_id := fnd_gfm.get_file_id(access_id);

...

END;
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

O Tim Hall tem uma solução pra isso também.
File Upload and Download Procedures

Oracle provide a mechanism to upload and download files directly from the database using a Database Access Descriptor (DAD). In this article I'll demonstrate how it works with a simple example.

First a Database Access Descriptor (DAD) must be created.

Access the database HTTP server main page via a browser (http://yourServer:7777/). The correct port number is listed in the $ORACLE_HOME/Apache/Apache/setupinfo.txt file
Click on the "Mod_plsql Configuration Menu" link.
Click on the "Gateway Database Access Descriptor Settings" link.
Click on the "Add Default (blank configuration)" link.
Enter UTILS as the Database Access Descriptor Name. This will be used in the requesting URL.
Enter the username (UTILS), password (UTILS) and connect string (W2K1) for the desired database connection.
Select the "Basic" authentication mode.
Enter "documents" for the Document Table.
Enter "docs" for the Document Access Path.
Enter "document_api.download" for the Document Access Procedure.
Click the OK button at the top right of the screen.

For the upload to be successful the documents table must be created with the following structure.

Selecionar tudo

CREATE TABLE documents (
  name           VARCHAR2(256) UNIQUE NOT NULL,
  mime_type      VARCHAR2(128),
  doc_size       NUMBER,
  dad_charset    VARCHAR2(128),
  last_updated   DATE,
  content_type   VARCHAR2(128),
  blob_content   BLOB
)
/
Next we create a package specification which will contain all the necessary code.

Selecionar tudo

CREATE OR REPLACE PACKAGE document_api AS

PROCEDURE upload;
PROCEDURE upload (file  IN  VARCHAR2);
PROCEDURE download;
PROCEDURE download (file  IN  VARCHAR2);

END;
/
SHOW ERRORS
Then the package body.

Selecionar tudo

CREATE OR REPLACE PACKAGE BODY document_api AS

-- ----------------------------------------------------------------------------
PROCEDURE upload AS
-- ----------------------------------------------------------------------------
  l_real_name  VARCHAR2(1000);
BEGIN

  HTP.htmlopen;
  HTP.headopen;
  HTP.title('Test Upload');
  HTP.headclose;
  HTP.bodyopen;

  HTP.header(1, 'Test Upload');

  HTP.print('<form enctype="multipart/form-data" action="document_api.upload" method="post">');
  HTP.print('  File to upload: <input type="file" name="file"><br />');
  HTP.print('  <input type="submit" value="Upload">');
  HTP.print('</form>');

  HTP.bodyclose;
  HTP.htmlclose;
END upload;
-- ----------------------------------------------------------------------------


-- ----------------------------------------------------------------------------
PROCEDURE upload (file  IN  VARCHAR2) AS
-- ----------------------------------------------------------------------------
  l_real_name  VARCHAR2(1000);
BEGIN

  HTP.htmlopen;
  HTP.headopen;
  HTP.title('File Uploaded');
  HTP.headclose;
  HTP.bodyopen;
  HTP.header(1, 'Upload Status');

  l_real_name := SUBSTR(file, INSTR(file, '/') + 1);

  BEGIN
    -- Delete any existing document to allow update.
    DELETE FROM documents
    WHERE  name = l_real_name;

    -- Update the prefixed name with the real file name.
    UPDATE documents
    SET    name = l_real_name
    WHERE  name = file;

    HTP.print('Uploaded ' || l_real_name || ' successfully.');
  EXCEPTION
    WHEN OTHERS THEN
      HTP.print('Upload of ' || l_real_name || ' failed.');
      HTP.print(SQLERRM);
  END;
  HTP.br;

  -- Create some links to demonstrate URL downloads.
  HTP.br;
  HTP.print('URL Downloads:');
  HTP.br;
  FOR cur_rec IN (SELECT name FROM documents) LOOP
    HTP.anchor('docs/' || cur_rec.name, 'docs/' || cur_rec.name);
    HTP.br;
  END LOOP;

  -- Create some links to demonstrate direct downloads.
  HTP.br;
  HTP.print('Direct Downloads:');
  HTP.br;
  FOR cur_rec IN (SELECT name FROM documents) LOOP
    HTP.anchor('document_api.download?file=' || cur_rec.name, 'document_api.download?file=' || cur_rec.name);
    HTP.br;
  END LOOP;

  HTP.bodyclose;
  HTP.htmlclose;
END upload;
-- ----------------------------------------------------------------------------


-- ----------------------------------------------------------------------------
PROCEDURE download IS
-- ----------------------------------------------------------------------------
  l_filename  VARCHAR2(255);
BEGIN
  l_filename := SUBSTR(OWA_UTIL.get_cgi_env('PATH_INFO'), 2);
  WPG_DOCLOAD.download_file(l_filename);
EXCEPTION
  WHEN OTHERS THEN
    HTP.htmlopen;
    HTP.headopen;
    HTP.title('File Downloaded');
    HTP.headclose;
    HTP.bodyopen;
    HTP.header(1, 'Download Status');
    HTP.print('Download of ' || l_filename || ' failed.');
    HTP.print(SQLERRM);
    HTP.bodyclose;
    HTP.htmlclose;
END download;
-- ----------------------------------------------------------------------------


-- ----------------------------------------------------------------------------
PROCEDURE download (file  IN  VARCHAR2) AS
-- ----------------------------------------------------------------------------
  l_blob_content  documents.blob_content%TYPE;
  l_mime_type     documents.mime_type%TYPE;
BEGIN
  SELECT blob_content,
         mime_type
  INTO   l_blob_content,
         l_mime_type
  FROM   documents
  WHERE  name = file;

  OWA_UTIL.mime_header(l_mime_type, FALSE);
  HTP.p('Content-Length: ' || DBMS_LOB.getlength(l_blob_content));
  HTP.p('Content-Disposition: filename="' || file || '"');
  OWA_UTIL.http_header_close;

  WPG_DOCLOAD.download_file(l_blob_content);
EXCEPTION
  WHEN OTHERS THEN
    HTP.htmlopen;
    HTP.headopen;
    HTP.title('File Downloaded');
    HTP.headclose;
    HTP.bodyopen;
    HTP.header(1, 'Download Status');
    HTP.print(SQLERRM);
    HTP.bodyclose;
    HTP.htmlclose;
END download;
-- ----------------------------------------------------------------------------

END;
/
SHOW ERRORS
Once this code is compiled a file can be uploaded by using the following URL format.

# Format

Selecionar tudo

http://<server-name>:<port>/pls/<DAD>/document_api.upload
# Example

Selecionar tudo

http://myserver:7777/pls/UTILS/document_api.upload
Alternatively, the upload can be performed by adjusting the form action in the upload.html file.

The second overload of the upload procedure does not really upload the file as this is done automatically by the DAD. It simply allows you to perform additional processing if necessary. Oracle prefixes a the file name with a generated folder name to reduce the posibility of name conflicts. In this example the files are renamed to their original names.

In addition the upload code produces two types of links to test the download code. The first set of links use the "document access path" and the "document access procedure" defined in the DAD. These allow access to the files using a regular URL, masking the procedure call which actually returns the file. Using the document access path in the URL causes the DAD to call the document access procedure. The requested file name must be retrieved from the URL and used in the WPG_DOCLOAD.download_file procedure call.

The second set of links call an alternative download procedure directly. In this case file name must be specified as a parameter.

For more information see the DAD documentation loaded on your server. This is typically accessed using a URL like the following.

Selecionar tudo

http://yourserver:7777/pls/simpledad/admin_/help/feature.htm#1004906
Hope this helps. Regards Tim...
Responder
  • Informação
  • Quem está online

    Usuários navegando neste fórum: Nenhum usuário registrado e 8 visitantes