Oracle Apex 4.2 custom file download error 404 Not Found or 403 Forbidden - blob

I'am using Oracle Apex and I have a form to upload and store a file in a table via wwv_flow_files
In order to download the file I am using the procedure download_my_file
When I try to click the link and download the error 404 is raised
My environment is
Application Express 4.2.6.00.03
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
Oracle Rest Data Service 3.0.9.348.07.16
Thanks to any suggestion or advice
EDIT:
I check the stored procedure in Apex going Home->SQL Workshop->SQL Commands
If I copy and paste the code and instead of the parameter I use a known ID the execution is successful.
With the syntax download_my_file?p_file=#ID# url is
http://myhost:8080/ords/download_my_file?p_file=24255
the error 404 Not found is raised.
With the syntax #OWNER#.download_my_file?p_file=#ID# url is
http://myhost:8080/ords/mypdb.download_my_file?p_file=24255
the error 403 Forbidden is raised.
EDIT 2 : as requested here is the procedure
PROCEDURE download_my_file(p_file in number) AS
v_mime VARCHAR2(48);
v_length NUMBER;
v_file_name VARCHAR2(2000);
Lob_loc BLOB;
BEGIN
SELECT files_mime_type, files_content, files_name, dbms_lob.getlength(files_content)
INTO v_mime,lob_loc,v_file_name,v_length
FROM pub_db0files
WHERE files_id = p_file;
--
-- set up HTTP header
--
-- use an NVL around the mime type and
-- if it is a null set it to application/octect
-- application/octect may launch a download window from windows
owa_util.mime_header( nvl(v_mime,'application/octet'), FALSE );
-- set the size so the browser knows how much to download
htp.p('Content-length: ' || v_length);
-- the filename will be used by the browser if the users does a save as
htp.p('Content-Disposition: attachment; filename="'||replace(replace(substr(v_file_name,instr(v_file_name,'/')+1),chr(10),null),chr(13),null)|| '"');
-- close the headers
owa_util.http_header_close;
-- download the BLOB
wpg_docload.download_file( Lob_loc );
end download_my_file;

According to documentation «Fusion Middleware User's Guide for mod_plsql» regarding to wpg_docload.download_file we have to «add the line WindowsFileConversion Off to DAD entry.
Open the file ORACLE_INSTANCE\config\OHS\ohs1\mod_plsql\dads.conf.
Locate the DAD used to access the application.
Add the line WindowsFileConversion Off to this DAD entry.
Save the file.
Restart Oracle HTTP Server.
If you do not update the DAD configuration, you will experience failures while downloading documents which contain 0x5c in the filename. For example:
In Oracle Portal, you will see the download error:
Error: Document not found (WWC-46000)
When using mod_plsql against your own PL/SQL application, file downloads will result in the error:
HTTP-404 Not Found
https://docs.oracle.com/cd/E28280_01/portal.1111/e12041/concept.htm#YPMOD001

Related

Trying to import Datapump dump into remote Oracle Server via SQL

I am trying to import a datapump dump file into a remote server via SQLPlus.
So, local machine -> remote oracle Server
Dump file is on local machine on a SMB share.
I have written a little script for that operation, however it fails with errors.
The Datapump Directory exists (SMB share on local machine, DIRECTORY is pointing to said share)
My script:
DECLARE
ind NUMBER; -- Loop index
h1 NUMBER; -- Data Pump job handle
percent_done NUMBER; -- Percentage of job complete
logfileName VARCHAR2(30);-- Name of the Logfile
job_state VARCHAR2(30); -- To keep track of job state
le ku$_LogEntry; -- For WIP and error messages
js ku$_JobStatus; -- The job status from get_status
jd ku$_JobDesc; -- The job description from get_status
sts ku$_Status; -- The status object returned by get_status
BEGIN
h1 := DBMS_DATAPUMP.OPEN('IMPORT','FULL',NULL,'IMPORT_XYDESCRIPTOR');
DBMS_DATAPUMP.ADD_FILE(h1,'dump.dmp','DPIMP_REMOTE',NULL,DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE,1);
DBMS_DATAPUMP.SET_PARAMETER(h1,'TABLE_EXISTS_ACTION','APPEND');
DBMS_DATAPUMP.START_JOB(h1);
[... more stuff...]
However I get the following error, when I execute that script as SYSDBA:
DECLARE
*
ERROR at line 1:
ORA-39001: invalid argument value
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
ORA-06512: at "SYS.DBMS_DATAPUMP", line 4056
ORA-06512: at "SYS.DBMS_DATAPUMP", line 4307
ORA-06512: at line 15
line 15 is this line:
DBMS_DATAPUMP.ADD_FILE(h1,'dump.dmp','DPIMP_REMOTE',NULL,DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE,1);
I don't really get why I get an invalid argument value error, the command is exactly as the Oracle wiki dictates.
Can someone help me on what I am doing wrong?
Maybe the thing I try isn't even possible?

DB2 - AUTONOMOUS Stored Procedure

I would like to write an AUTONOMOUS stored procedure (native). I'm using the DB2 database (V11.01)
CREATE PROCEDURE SP_LOG (IN p_field1 char(2)
,IN p_field2 varchar(50)
,IN p_field3 varchar(50)
,IN p_field4 varchar(3926) )
VERSION V1
ISOLATION LEVEL CS
WLM ENVIRONMENT FOR DEBUG MODE WLMENV1
RESULT SETS 0
LANGUAGE SQL
ALLOW DEBUG MODE
AUTONOMOUS
BEGIN
...
...
END
I'm using IBM DATA STUDIO 4.1.1 and I get the following error:
Creazione di procedura memorizzata restituzioni
SQLCODE: -104, SQLSTATE: 42601. XXXXX.SP_LOG: 11: ILLEGAL SYMBOL
"". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: FOR.
SQLCODE=-104, SQLSTATE=42601, DRIVER=4.18.60 XXXXX.SP_LOG -
Distribuzione per il debug non riuscita. XXXXX.SP_LOG - Rollback
completato correttamente.
If you have any recommendations, I'd love to hear them!
Thanks :)
Good news, I found the issue.
This is a bug of IBM Data Studio (IT26018 - AUTONOMOUS KEYWORD IS NOT CONSIDERED AS A VALID KEYWORD FOR DB2 ZOSV11 AND V12 IN DS.4.1.3 - For more information click here.
Here's how I solved it:
I downloaded the new version (IBM DATA STUDIO 4.1.3) - Link
Installed the new version using IBM INSTALLATION MANAGER
I downloaded the FIX - Link
Installed the FIX (Instructions are included in the .ZIP file (open the "Hotfix Guide.pdf" file)

How do I reformat v$session.osuser?

I am trying to set up an Oracle WebLogic Datasource for my job. But every time I try to connect to the database, I get this error:
Connection test failed.
Message icon - Error Connection property: format error: Property is 'v$session.osuser' and value is 'Yann (Intern)'
I tried changing my username to "YannIntern" to remove the special characters, but the error is still the same and it also happens when I try to use Oracle SQL Developer. How can I stop the format error?
Java reads this from the user.name property which defaults from the os username. However, this can be overriden by setting -Duser.name=Yann
Here's an example in sqlcl
SQL> select sys_context('userenv', 'os_user') from dual;
SYS_CONTEXT('USERENV','OS_USER')
------------------------------------
klrice
<<< a short command to set java properties >>>
<<< which is the same as a -D property >>>
SQL> set property user.name kris
Setting user.name to kris (klrice)
SQL> #connect-klrice
Connected.
SQL> select sys_context('userenv', 'os_user') from dual;
SYS_CONTEXT('USERENV','OS_USER')
----------------------------------
kris
SQL>
Same happened to me, I have parenthesis in my computer's name. I spent a lot of time researching but finally, I have the solution (I created an account just to answer this haha). To solve this you have to:
-Go to the folder location where you installed SQL Developer.
-Then go to: \ide\bin\ide.conf
-At the end add the following line:
# Custom VM Option
AddVMOption -Duser.name=<YourUsername>
-Save the file, and restart SQL Developer, you will be able to connect and avoid that error message.

Oracle APEX - An unexpected error with the following message occurred: application/pdf

I have a pl/sql procedure that that downloads a blob file in pdf format from Jasper Server. In this procedure I have the following code which prompts the browser to download the file to my local drive.
begin
v_param_val (1) := 1;
owa.init_cgi_env (v_param_val);
htp.flush;
-- clear the output buffer and reset response state
htp.init;
owa_util.mime_header ('application/pdf', false);--,'UTF-8'
htp.p('Content-length: ' || v_lob_length);
htp.p('Content-Disposition: attachement; filename="'||v_file||'"' );
owa_util.http_header_close;
htp.showpage ();
wpg_docload.download_file(v_blobref);
exception
when timeout_on_resource then
raise_application_error (-00051,'No response from the server.');
when others then
htp.p('other error : ' || sqlerrm);
end;
The problem is, I have an oracle apex page that I use to call my procedure. The page passes through the values to be used as parameters in the call of the procedure. I have a an apex process that makes this happen...
declare
v_report_name reports_data.report_name%type;
begin
v_report_name := s_reports_data.get_report_name(:P31_AVAILABLE_REPORTS);
s_reports_data.generate_jasper_report(v_report_name, :P31_DATE_TO,
:P31_RESEARCH_STATION, :P31_DATE_FROM);
end;
No the following error comes up when I try to call the procedure.
An unexpected error with the following message occurred: application/pdf
It seems like the following line is the cause of the error.
owa_util.mime_header ('application/pdf', false);--,'UTF-8'
Or the following line.
wpg_docload.download_file(v_blobref);
Looking in the docs, the function seems to need 3 parameters. Have you tried
owa_util.mime_header('application/pdf', false, 'UTF-8')
I finally got rid of the problem I had. This is how my code looks like now and it works perfectly fine.
begin
sys.htp.init;
sys.owa_util.mime_header (nvl(v_mime,'application/octet'), false, 'UTF-8');
sys.htp.p('Content-length: ' || v_lob_length);
sys.htp.p('Content-Disposition: attachement; filename="'||v_file||'"' );
sys.owa_util.http_header_close;
sys.wpg_docload.download_file(v_blobref);
apex_application.stop_apex_engine;
exception when others then
sys.htp.prn('error: '||sqlerrm);
apex_application.stop_apex_engine;
end;

Running SQL in Stata

I am trying to load data from SQL server management studio into Stata. How do I get Stata to run the .sql file? I have used the -ado- procedure from another post, but it does not work because my database has a username and password.
Original -ado- code:
program define loadsql
*! Load the output of an SQL file into Stata, version 1.2 (dvmaster#gmail.com)
version 12.1
syntax using/, DSN(string) [CLEAR NOQuote LOWercase SQLshow ALLSTRing DATESTRing]
#delimit;
tempname mysqlfile exec line;
file open `mysqlfile' using `"`using'"', read text;
file read `mysqlfile' `line';
while r(eof)==0 {;
local `exec' `"``exec'' ``line''"';
file read `mysqlfile' `line';
};
file close `mysqlfile';
odbc load, exec(`"``exec''"') dsn(`"`dsn'"') `clear' `noquote' `lowercase' `sqlshow' `allstring' `datestring';
end;
help odbc discusses connect_options for connecting to odbc data sources. Two of which are u(userId) and p(password) which can be added to the original code written by #Dimitriy V. Masterov (see post here).
I believe you should be able to connect using SQL Server authentication by adding the u(string) and p(string) as additional options following syntax in the ado file, and then again down below following
odbc load, exec(`"``exec''"') dsn(`"`dsn'"')
This would also require that you pass these arguments to the program when you call it:
loadsql using "./sqlfile.sql", dsn("mysqlodbcdata") u(userId) p(Password)