"Internal Server Error" w Oracle 10g XE

0

Korzystając z webservice w Oracle 10g XE muszę stworzyć stronę z możliwością upload'u plików do bazy. Po poszukiwaniach na google znalazłem przykładowy kod umożliwiający wykonanie mojego zadania. Po kompilacji kodu jak wejdę na stronę wszystko wygląda dobrze. Stronka się wczytuje ale przy próbie upload'u dostaję komunikat "Internal Server Error".

Baza do której zapisywane są pliki:

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
)

Kod procedur PL/SQL:

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));
  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;
0

wykonaj zapytanie wstawiające dane z poziomu jakiegoś SQLa (np. SQLToolsa) i zobacz co dostaniesz

0
Misiekd napisał(a)

wykonaj zapytanie wstawiające dane z poziomu jakiegoś SQLa (np. SQLToolsa) i zobacz co dostaniesz

A jak takie zapytanie miałoby wyglądać [???] Bo nawet w procedurze upload'ującej nie ma inserta 8-O

0
BEGIN document_api.upload('sciezka/do/pliku'); END;</sql>
0
Misiekd napisał(a)
BEGIN document_api.upload('sciezka/do/pliku'); END;</sql>

Po uruchomieniu powyższego kodu dostaję takie błędy:

ORA-06502: PL/SQL: numeric or value error: NULL index table key value
ORA-06512: at "SYS.HTP", line 1536
ORA-06512: at "SYS.HTP", line 1709
ORA-06512: at "LAB9.DOCUMENT_API", line 56
ORA-06502: PL/SQL: numeric or value error: NULL index table key value
ORA-06512: at line 2

Jak w procedurze "upload" wyłącze wszystkie HTP to nie ma błędów ale też i nie ma danych w tabeli :-[

0

to też zrobiłeś?

This article is an update of a previous Oracle9i article, which includes some modified configuration steps necessary in Oracle 10g. For this procedure to work the HTTP Server software, available on the Companion CD, must be installed into a separate ORACLE_HOME, typically:
/u01/app/oracle/product/10.1.0/client_1
The example assumes the the ORACLE_HOME environment variable has been set to this path also:
ORACLE_HOME=/u01/app/oracle/product/10.1.0/client_1; export ORACLE_HOME
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. Add the following entry to the $ORACLE_HOME/Apache/modplsql/conf/dads.conf file:

<Location /pls/UTILS>
  SetHandler pls_handler
  Order deny,allow
  Allow from all
  AllowOverride None
  PlsqlDatabaseUsername         utils 
  PlsqlDatabasePassword         utils
  PlsqlDatabaseConnectString    dev
  PlsqlAuthenticationMode       Basic
  PlsqlDocumentTablename        utils.documents
  PlsqlDocumentPath             docs
  PlsqlDocumentProcedure        document_api.download
</Location>

Run the following command to obfuscate the DAD password:

cd $ORACLE_HOME/Apache/modplsql/conf/
perl dadTool.pl -o

Make sure the PlsqlDatabaseConnectString parameter value has a corresponding entry in the "$ORACLE_HOME/network/admin/tnsnames.ora" file for the client ORACLE_HOME. With this in place restart the HTTP server using the following commands:

$ORACLE_HOME/opmn/bin/opmnctl stopall
$ORACLE_HOME/opmn/bin/opmnctl startall
0
Misiekd napisał(a)

to też zrobiłeś?

This article is an update of a previous Oracle9i article, which includes some modified configuration steps necessary in Oracle 10g. For this procedure to work the HTTP Server software, available on the Companion CD, must be installed into a separate ORACLE_HOME, typically:
/u01/app/oracle/product/10.1.0/client_1
The example assumes the the ORACLE_HOME environment variable has been set to this path also:
ORACLE_HOME=/u01/app/oracle/product/10.1.0/client_1; export ORACLE_HOME
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. Add the following entry to the $ORACLE_HOME/Apache/modplsql/conf/dads.conf file:

<Location /pls/UTILS>
  SetHandler pls_handler
  Order deny,allow
  Allow from all
  AllowOverride None
  PlsqlDatabaseUsername         utils 
  PlsqlDatabasePassword         utils
  PlsqlDatabaseConnectString    dev
  PlsqlAuthenticationMode       Basic
  PlsqlDocumentTablename        utils.documents
  PlsqlDocumentPath             docs
  PlsqlDocumentProcedure        document_api.download
</Location>

Run the following command to obfuscate the DAD password:

cd $ORACLE_HOME/Apache/modplsql/conf/
perl dadTool.pl -o

Make sure the PlsqlDatabaseConnectString parameter value has a corresponding entry in the "$ORACLE_HOME/network/admin/tnsnames.ora" file for the client ORACLE_HOME. With this in place restart the HTTP server using the following commands:

$ORACLE_HOME/opmn/bin/opmnctl stopall
$ORACLE_HOME/opmn/bin/opmnctl startall

Nie mogę tego zrobić bo nie ma takich folderów a i wyszukiwanie plików też nic nie dało :-/ (za wyjątkiem tego: tnsnames.ora)
Nie wiem czy tego Apache'a mam sam zainstalować. Jeśli tak to czemu stronki pisane w PL/SQL normalnie chodzą?

1 użytkowników online, w tym zalogowanych: 0, gości: 1