File download/code
Hello,
I'm using JDeveloper 11.1.1.3. I'm trying to read the value of an attribute in an "ADF Quick Query with Table" called "Filename" and compare it with list of files i have in the directory "C:\\demos". Once the value is matched, the file with the corresponding Filename should be download. However, when i press the download button which has an af:downloadActionlistener binded to my bean i get an empty page. Can anyone please check my code:
public void ACDownloadFile(FacesContext facesContext, OutputStream outputStream)
InputStream in;
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("SearchAdministrationCircularsView1Iterator");
Row selectedrow = dciter.getCurrentRow();
File root = new File("C:\\demos");
String att = "";
if (selectedrow != null) {
att = (String)selectedrow.getAttribute("Filename");
File[] listOfFiles = root.listFiles();
for(int i = 0; i < listOfFiles.length; i++){
String filename = listOfFiles.getName();
if(filename.equalsIgnoreCase(att)){//attname
try {
in = new FileInputStream(listOfFiles[i]);
IOUtils.copy(in, outputStream);
in.close();
outputStream.flush();
catch (IOException e)
e.printStackTrace();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "");
FacesContext.getCurrentInstance().addMessage(null, msg);
i=listOfFiles.length;
}Thanks,
Mohamed
Mohamed,
the code look OK. One thing which you can do better is not to iterate over all files present in the directory, but use the File.exists(); method with the file name you are getting from the UI.
If the file exisits you get true as return value otherwise false.
File root = new File("C:\\demos");
String att = "";
if (selectedrow == null) {
return;
att = (String)selectedrow.getAttribute("Filename");
File downloadFile = new File("C:\\demos\\"+attr);
if (!downloadFile.exists()) {
return;
try {
in = new FileInputStream(listOfFiles);
IOUtils.copy(in, outputStream);
in.close();
outputStream.flush();
catch (IOException e) {
e.printStackTrace();
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "");
FacesContext.getCurrentInstance().addMessage(null, msg);
Should do the it. To avoid problems the the case the file name is given from the UI you should store all files in upper or lowercase.
The there are some other flaws in your code like you test in the file name is given from the UI, but if it's not you still iterate over all files. Next you don't stop the iteration of the files once you found the matching file.
Have you debug the code and verified that the fileyou are looking for is found?
Timo
Similar Messages
-
File download code works without error, but no file is downloaded
Hello,
I have a very strange problem -- I am trying to download a
simple file from a server, using virtually identical code to what
is in the FileReference.download() examples. My code executes
flawlessly, I get the browse window to select the location to save
and name of the file, as expected. I click "Save" in the file
dialog, and the window disappears -- but no file. I know my URL is
right, because I can test the URL from the browser, and I get the
file back. But here's the even weirder thing: I threw TCPMon in
between Flex and the server, and discovered that the
FileReference.download() method isn't even sending a request to the
server. If I try the exact same URL through a browser, TCPMon shows
both the request and response. But Flex never registers a request
at all.
Help! I have 100% error free code that follows the
documentation examples but doesn't request or download the file.
Your help is appreciated!
Thanks,
BradI found the answer to my problem, but now I want to know WHY
this is, and if it is considered a bug by Adobe -- if anyone out
there has an explanation, that would be great.
I implemented the full set of event handlers, and guess what
-- not only was I not getting any HTTP request being made, but I
also didn't get any event callbacks. Bottom line, I think I found
an Actionscript bug.
The answer to the $64,000 question is this: when the
FileReference object goes out of scope (I had it declared locally),
because the download() call is asynchronous, it doesn't call event
handlers or make a request. It must be garbage collecting it. So
you have to have your variable as a member, not a local variable.
Weird. I find no other objects in Actionscript work like that. I
wonder if it has something to do with the fact that the call
crosses the native boundary (because it is leaving the Flash
sandbox, and interacting with the browser/native OS.
To me, that's like prematurely killing a thread before it has
completed processing just because it has no parent object with a
reference to it. In general, most rules for garbage collection I've
seen in various platforms require either a parent object or thread
of processing to prevent cleanup.
If anyone has an explanation, I'm all ears!
Thanks,
Brad -
APEX 4.0: error while opening a XLS file downloaded from interactive report
Hi,
I'm getting below error while opening a XLS file downloaded from an interactive report (APEX 4.0).
"The file you trying to open, 'customer_2.xls', is in a different format than specified by the file extension.
Verify that the is not corrupted and is from a trusted source before opening file. Do you want to open file."
Yes No Help
May be this one Apex 4.0 issue.
please help me.
Thanks
MukeshHi,
is the next part of the code correct.
What i mean is packing of the attachment, finding out the size of pdf file and doc type as PDF.
You can also try below link..
Link: [http://wiki.sdn.sap.com/wiki/display/Snippets/SENDALVGRIDASPDFATTACHMENTTOSAPINBOXUSINGCLASSES]
Hope this helps.
Regards,
-Sandeep -
TAx Reporter Temse Files Download Automation
Hi,
I have a reuiqrement to download the Temse files generated in Tax Reporter. I have completed the code and it works fine if we run the program in foreground. But when I run the same program in background some Temse files downloaded have junk characters. If I download the same Temse file in foreground it works fine.
There seems to be some issue with the FM when I run my progam in background.
I have searched SDN and SAP Notes for any clues but did not get any.
REPORT ZPHOP_TEMSE NO STANDARD PAGE HEADING
LINE-SIZE 1023
LINE-COUNT 65
MESSAGE-ID zz.
DATA: BEGIN OF tape OCCURS 1,
DATA(2000),
END OF tape.
DATA: force_ascii type c VALUE 'T'.
DATA: BEGIN OF int_msgs2 OCCURS 10,
errnum(2) TYPE c,
text1(8) TYPE c,
text2(60) TYPE c,
END OF int_msgs2.
DATA: BEGIN OF g_int_temse OCCURS 0,
dname LIKE TST01-dname,
dpart LIKE TST01-dpart,
dcretime LIKE TST01-DCRETIME,
dcreater LIKE TST01-DCREATER,
END OF g_int_temse.
DATA: record_length TYPE i VALUE 275,
data_length TYPE i,
convert_to_ebcdic,
filesize TYPE i,
number_of_records TYPE i VALUE 1,
filetype(3) VALUE 'BIN',
conv TYPE REF TO cl_abap_conv_out_ce,
dline TYPE REF TO data,
dtab TYPE REF TO data,
p_compid(4),
p_pswd(8),
g_str(2000),
uc_filename TYPE string.
DATA: l_nm_fixed_record.
CONSTANTS: c_lpath TYPE pathintern VALUE 'ZOUT'.
TABLES: TST01, ZPHOPFLS, ZTEMSE_LOG, V_5UXY_A.
FIELD-SYMBOLS: <dtab> TYPE STANDARD TABLE,
<dline> TYPE ANY.
INCLUDE: dbpnpcom. " No logical database Do not modify!
INCLUDE: zphoptop, " Top Include Do not modify!
zphopfil. " File inlcude Do not modify!
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-T01.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-001.
SELECT-OPTIONS s_temse FOR TST01-dname NO INTERVALS.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE text-T02.
SELECT-OPTIONS s_cai FOR TST01-DCREATER NO INTERVALS.
SELECT-OPTIONS s_date FOR sy-datum.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE text-T03.
PARAMETERS: p_ifid LIKE t9aoa-if_id MODIF ID DIS ,
p_fileid LIKE t9aoa-file_id MODIF ID DIS,
p_unixf(60) LOWER CASE MODIF ID DIS,
p_uxdir TYPE pathextern LOWER CASE MODIF ID DIS,
p_dstfil(45) LOWER CASE MODIF ID DIS.
SELECTION-SCREEN END OF BLOCK B3.
PARAMETERS: p_skip AS CHECKBOX.
DATA: ws_unixr LIKE p_unixf,
ws_trans LIKE p_unixf.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'DIS'.
screen-output = '1'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
INITIALIZATION.
p_ifid = 'PAYFLS'.
p_compid = 'HR00'.
p_fileid = '01'.
p_unixf = 'AFS'.
p_pswd = 'chevr123'.
p_skip = 'X'.
-End of Initialization--
PERFORM get_physical_path.
FORMAT COLOR COL_HEADING.
WRITE: /01 text-t04,
10 sy-pagno,
41 text-t05,
110 text-t06,
123 sy-datum.
WRITE: /01 text-t08,
14 sy-repid,
110 text-t07,
125 sy-uzeit.
FORMAT COLOR OFF.
SKIP.
WRITE: /(20) text-T21 CENTERED COLOR COL_HEADING,
(15) text-T22 CENTERED COLOR COL_HEADING,
(20) text-T23 CENTERED COLOR COL_HEADING,
(15) text-T24 CENTERED COLOR COL_HEADING,
(40) text-T25 CENTERED COLOR COL_HEADING.
START-OF-SELECTION.
*Do not allow background processing
*Check if the Temse file and CAI both are entered
IF NOT S_TEMSE IS INITIAL AND NOT S_CAI IS INITIAL.
MESSAGE W999 WITH TEXT-E01.
ELSEIF S_TEMSE IS INITIAL AND S_CAI IS INITIAL.
MESSAGE W999 WITH TEXT-E02.
ENDIF.
Collect all temse filenames from TST01 into an internal table.
IF NOT s_temse IS INITIAL.
SELECT dname dpart dcretime dcreater FROM TST01 INTO TABLE g_int_temse
WHERE dname in s_temse
AND dpart EQ '1'.
ELSE.
SELECT * FROM TST01
WHERE DCREATER in s_cai
AND DPART EQ '1'.
IF TST01-DCRETIME(8) GE s_date-low
AND TST01-DCRETIME(8) LE s_date-high.
MOVE-CORRESPONDING TST01 TO g_int_temse.
APPEND g_int_temse.
ENDIF.
ENDSELECT.
ENDIF.
SORT g_int_temse BY DNAME DPART DCRETIME.
LOOP AT g_int_temse.
Check if the temse file is already processed in ZTEMSE_LOG table.
SELECT SINGLE * FROM ZTEMSE_LOG
WHERE DNAME = g_int_temse-dname.
IF sy-subrc EQ 0.
error. Temse already processed
CONTINUE.
ENDIF.
Check if the temse file bieng processed is the eligible temse file
SELECT SINGLE * FROM V_5UXY_A
WHERE TSOBJ = g_int_temse-dname.
IF sy-subrc EQ 0.
SELECT SINGLE * FROM ZPHOPFLS
WHERE TAXAU = V_5UXY_A-TAXAU
AND TXFRM = V_5UXY_A-TXFRM.
IF sy-subrc EQ 0.
Generate the filename for the target destination
CONCATENATE ZPHOPFLS-FILENAME '.' sy-datum '.' sy-uzeit INTO p_dstfil.
ELSE.
error. Script not maintained in ZPHOPFLS table
CONTINUE.
ENDIF.
ELSE.
error. Temse file is not the latest processed file.
CONTINUE.
ENDIF.
CALL FUNCTION 'RP_TS_OPEN'
EXPORTING
tsobj = g_int_temse-dname
versn = g_int_temse-dpart
empfg = 'RPUTSVUM'.
COMMIT WORK.
REFRESH tape.
CLEAR tape.
Einlesen von der TemSe
CALL FUNCTION 'RSTS_READ'
EXPORTING
PARTS1BY1 = 'X'
TABLES
datatab = tape.
CALL FUNCTION 'RSTS_CLOSE'.
Read the 1st line which is supposed to contains info important for
the downloading procedure. The syntax of the line is :
SAPxxxnnnyyyy - the 1st 3 char 'SAP' indicates this line contains
download related info. xxx can either be 'ASC' (for ASCII) or 'EBC'
(for EBCDIC). nnn is the length of each record, e.g. 128 for SSA disk
format, 275 for SSA tape format etc. yyyy can either be 'CRLF' (each
record is delimited by CRLF) or blank (no CRLF).
After processing the 1st line, the line is deleted from the internal
table. Downloading begins on the 2nd line.
READ TABLE tape INDEX 1.
IF tape-data(3) EQ 'SAP'.
IF tape-data+3(3) EQ 'EBC'.
convert_to_ebcdic = 'x'.
ELSEIF tape-data+3(3) EQ 'ASC'
AND force_ascii EQ 'T'.
filetype = 'ASC'.
ENDIF.
IF tape-data+6(3) NA '*'.
record_length = tape-data+6(3).
ELSE.
record_length = tape-data+13(4).
ENDIF.
IF tape-data+9(4) EQ 'CRLF'.
data_length = record_length + 2.
ELSE.
data_length = record_length.
ENDIF.
DELETE tape INDEX 1.
ELSE.
data_length = record_length.
ENDIF.
Transfer the Temse file data to Unix file.
PERFORM transfer_file.
Update the Log table with the temse details.
ZTEMSE_LOG-dname = g_int_temse-dname.
ZTEMSE_LOG-txcmp = V_5UXY_A-taxau.
ZTEMSE_LOG-txfrm = V_5UXY_A-txfrm.
ZTEMSE_LOG-filename = ws_unixr.
ZTEMSE_LOG-DCREATER = g_int_temse-dcreater.
INSERT ZTEMSE_LOG.
WRITE: /(20) ZTEMSE_LOG-dname,
(15) ZTEMSE_LOG-txcmp,
(20) ZTEMSE_LOG-txfrm,
(15) ZTEMSE_LOG-dcreater,
(40) ZTEMSE_LOG-filename.
ENDLOOP.
*& Form get_physical_path
Get Physical directory name for the given logical path name
FORM get_physical_path .
CALL FUNCTION 'ZFILE_GET_PATH_NAME'
EXPORTING
LOGICAL_PATH = c_lpath
IMPORTING
FILE_NAME_PATH = p_uxdir
EXCEPTIONS
PATH_NOT_FOUND = 1
MISSING_PARAMETER = 2
OPERATING_SYSTEM_NOT_FOUND = 3
FILE_SYSTEM_NOT_FOUND = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " get_physical_path
*& Form TRANSFER_FILE
FORM transfer_file.
p_unixf = 'AFS'.
Concatenate Date with Unix File name
CONCATENATE p_unixf '.' p_compid '.' p_ifid '.' sy-datum '.' sy-uzeit INTO ws_unixr.
Concatenate Unix Directory with Unix File for Outbound
CONCATENATE p_uxdir ws_unixr INTO p_unixf.
PERFORM open_files USING p_unixf.
LOOP AT tape.
g_str = tape-data(record_length).
TRANSFER g_str TO p_unixf LENGTH record_length.
IF sy-subrc <> 0.
MESSAGE ID '00' TYPE 'E' NUMBER '398' WITH 'sy-subrc:' sy-subrc
' Error Transferring to: ' p_unixf.
ENDIF.
ENDLOOP.
PERFORM close_files USING p_unixf.
ENDFORM. " TRANSFER_FILE
Can anyone please check and tell me what I need to overcome this problem.Hi Bhaskar,
I also have the same requirement to upload TemSe files in to application server.
In FDTA tcode after we enter company code and click on enter.
In the second screen checking and line item and go to edit and click on download button.
Here we see a popup with default file name, and when we say ok the file will get downloaded into C:\.....
Here our req is to upload the file automatically pick up via batch job and place it in the in to the application server and from there it should be placed in the Netwrok server (UNIX).
Pls provide me with suitable code so that i can finish it off.I tried a lot but did not work.
Thanks. -
Filename on file download from jsp
This may help:
----- Original Message -----
From: "Erik Lindquist" <[email protected]>
Newsgroups: weblogic.developer.interest.jsp
Sent: Wednesday, June 28, 2000 6:20 PM
Subject: How to dynamically display images in JSPs
> This took a little while to figure out so I thought I'd share. After
> doing some research I was led to the following approach on how to load
> images from an Oracle database into a JSP:
>
> The "main" JSP:
>
> <HTML>
> <head>
> <title>Image Test</title>
> </head>
> <body>
> <center>
> hello
> <P>
> <img border=0 src="getImage.jsp?filename=2cents.GIF">
> <P>
> <img border=0 src="getImage.jsp?filename=dollar.gif">
> <P>
> world
> </body>
> </HTML>
>
>
> And this is the image getter:
>
> <% try {
> response.setContentType("image/gif");
> String filename = (String) request.getParameter("filename");
> java.sql.Connection conn =
> java.sql.DriverManager.getConnection("jdbc:weblogic:pool:orapool"); //
> connect to db
> java.sql.Statement stmt = conn.createStatement();
> String sql = "select image from testimage where filename = '" +
> filename + "'";
> java.sql.ResultSet rs = stmt.executeQuery(sql);
> if (rs.next()) {
> byte [] image = rs.getBytes(1);
> java.io.OutputStream os = response.getOutputStream();
> os.write(image);
> os.flush();
> os.close();
> }
> conn.close();
> }
> catch (Exception x) { System.out.println(x); }
> %>
>
>
> The thing to note is that there are no <%@ page import="..." %> or <%@
> page contentType="..." %> tags - just the single scriptlet. It
> seems that for every "<%@" the weblogic compiler sees it puts
> out.print("\r\n"); statements in the generated java source.(???) I
> don't know much about how browsers work but I think that once it sees
> flat ascii come at it it treats everything that follows as text/plain
> which is incorrect for the binary stream that's being sent. Another
> work around was to set out = null; but that's kind of ugly and might
> produce server errors. The real fix is to write a bean to handle images
> which I'll work on next (does anybody have any hints on how to do
> that?)
Cameron Purdy
[email protected]
http://www.tangosol.com
WebLogic Consulting Available
"Ramesh" <[email protected]> wrote in message
news:[email protected]...
>
> Hi,
>
> Even I could download the files with this technique, I couldn't open the
file downloaded. It seems the file is getting currepted during tranfer.. Can
u help me in this regard please?
>
> Thank u
> Ramesh
>
> [email protected] (Anders B. Jensen) wrote:
> >In an Web-application written in Java Server Pages it should be possible
> >for the user to download data from the web-server. The data will never
> >exist as a file on the web-server, only in the PrintWriter object, out.
> >To force the Internet Explorer (IE) to show the download dialog window
> >the Contenttype of the HTTP-header have been set to "html/transfer". The
> >question is:
> >
> >Is it possible to set the filename appearing in the download dialog
> >appearing on the client?
> >
> >
> >Below is a listing of the source-code:
> >
> ><%@ page extends="com.beasys.portal.admin.PortalJspBase"%>
> ><jsp:useBean id="download" scope="session" class="dk.lec.DownloadData" />
> >
> ><%
> > String tmpstr;
> > response.setContentType("html/transfer");
> > out.clear();
> > tmpstr=download.getStrbuffer().toString();
> > out.println(tmpstr.trim());
> >%>
> >
> >
> >Anders B. Jensen
> >Consultant, Research & Development
> >LEC AS
> >
> >Remove the SPAMLESS to mail me.
>
-
Can not open file download prompt in portal web app.
Hi folks,
I am migrating existing Struts app into portal web app and currently stuck on the following problem.
In existing app, Struts action calls servlet that generates excel file, sets response headers:
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment;filename=thename.csv");
that brings up "file download" prompt window.
In portal app, the same code writes excel file content into browser window instead of the prompt.
Has anyone had to deal with similar problem? Any help will be greatly appreciated.
Alex.
Version of portal used is 8.1 SP5
Struts - 1.1Problem is resolved. For those who might be interested - specifying redirect=true on forward to servlet did the trick.
-
OraRRP Error with "Unable to copy data file;Error code 2, check disk space"
Hi,
Some users get this message -"Unable to copy data file;Error code 2, check disk space" when run report with orarrp, but most users do not get it.
I check free space at both server and client side, they are very sufficient.
I also checked directory exists for REPORTXX_TMP variable.
My user call reports via URL (rwservlet) and it occur for all reports.
How I can solve this problem?
Thanks in advance.
Tawatchai R.Hi,
have the same problem now. One user has temporarily problems to download .rrpa files via URL (rwservlet) request. Error code: -"Unable to copy data file;Error code 2, check disk space". Did you get a solution??
Thanks in advance. Axel -
Issue with File Download(messageDownload) on Search Page.
Hi,
I created a custom OAF search page which fetches values from one table. The document in getting stored in my custom table in a BLOB colums and NOT in FND_LOBS.
The table has 3 collumns along with others:
1st is primary key (Record_Seq) ==> number data type
2nd to store actual file name (File1Name) ==> varcahar2 data type
3rd to store the actual uploaded data (File1Data) ==> BLOB data type
The reason for having the “File1Name” is so that I can display the original file name of the document that was uploaded, instead of just the “view” in the search page results .
On the File1Data BLOB and created a messageDownload for that under query results table with following details:
ID : File1Data
ItemStyle : messageDownload
FileMIME Type : pdf
Datatype : BLOB
View Instance : LacEmpExposureVO1
view Attribute : File1Name
File View Attribute : File1Data
When I click on the "File1Name" data hyperlink, it is opening only the first document corresponding to the first record in the search page results.
For example, If my search page returns 10 rows then when I click on the file1name on any row, It is open the first row file name only.
I have a primary key column(RECORD_SEQ) in the Table / EO / VO which is displayed in the search page results.
Also one weird thing is happening:
If I try to do this more than 2 times then it is opening the update page with the first record from the search page results…
I tried to print the context and it is nul the first time, But the second time then context is changing to "update". Dont know how this is happening????
Any advice is greatly appreciated as it is very crucial for me to get this resolved ASAP. I have looked at several forums and did a lot of things as advised in the forums . But nothing seems to work for me.
Thanks,
Mir
CO code for the search page
===========================
if (pageContext.getParameter("Create")!= null)
System.out.println("Into LacEmpExposureCO in PROCESS FORM REQUEST with Context of CREATE");
pageContext.setForwardURL
("OA.jsp?page=/lac/oracle/apps/lac/lacempexposure/webui/LacEmpExposureCreatePG",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true, //Retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_YES,
OAWebBeanConstants.IGNORE_MESSAGES);
else if ("update".equals(pageContext.getParameter(EVENT_PARAM)))
System.out.println("Into LacEmpExposureCO in PROCESS FORM REQUEST with Context of UPDATE");
System.out.println("LacEmpExposureCO ==> RecordSeq in PROCESS FORM REQUEST is: " + RecordSeq);
HashMap params = new HashMap(1);
params.put("RecordSeq", RecordSeq);
pageContext.setForwardURL
("OA.jsp?page=/lac/oracle/apps/lac/lacempexposure/webui/LacEmpExposureUpdatePG",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
params,
true, //Retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO, // Do not display breadcrumbs
OAWebBeanConstants.IGNORE_MESSAGES);
else {
String strEvent = pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM);
System.out.println(strEvent);
System.out.println("Into the last ELSE part in LacEmpExposureCO.java");Duplicate post -- Issue with File Download(messageDownload) on Search Page.
-
Hi All,
I have written a code that downloads a file from server using the following link given by Frank,
File download from server
I am able to get a open/save/cancel dialog with help of this. But issue is that applications of kind .doc/.xls/.ppt gets opened (If user clicks open) right in the internet explorer window instead of getting opened in a new office application....
However .pdf runs fine.
Can any thing be done for this???
Any help....
Regards,
AmittHi,
what do you have for the content disposition header?
Try this:
response.setHeader("Cache-Control", "max-age=0");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fname + "\"");
response.setContentType("application/x-download");Brenden -
Hi All,
I have designed an APEX application to download multiple files. I have check box in each row of the file name and a download button.
When the users checks set of checkboxes and click on the "Download" Button, i am expecting the marked files to be downloaded. I am encountering the below issues in this implementation(i.e single file download is fine):
1. When ticks all the check boxes and click download, the files are never downloading. The target URL goes something like this :
www.example.com/abc/bcd/wwv_flow.accept
and there is a cross icon in the new page. No download happening.
2. When ticks few files and leave rest of the files un-checked, there are either junk charactes in target page (or) only the last checked box file alone downloading.
Please refer the code below and advice. Thanks very much in advance.
Code:
=====
declare
check_box_val varchar2(500):=' ';
file_name varchar2(500):=' ';
begin
for i in 1..htmldb_application.g_f01.count
loop
check_box_val:=nvl(htmldb_application.g_f02(i),' ');
if(check_box_val<>' ') then
sho_pdf(check_box_val);
end if;
end loop;
exception
when others then
null;
end;
sho_pdf.sql
========
CREATE OR REPLACE PROCEDURE FDM_UAT14.sho_pdf(p_file in varchar2)
AS
l_blob BLOB;
l_bfile BFILE;
BEGIN
DBMS_LOB.createtemporary (l_blob, TRUE, DBMS_LOB.SESSION);
l_bfile := BFILENAME ('UPDOWNFILES_DIR', p_file);
DBMS_LOB.fileopen (l_bfile);
DBMS_LOB.loadfromfile (l_blob, l_bfile, DBMS_LOB.getlength (l_bfile));
DBMS_LOB.fileclose (l_bfile);
OWA_UTIL.mime_header ('application/octet',
bclose_header => FALSE);
HTP.p ('Content-length: ' || DBMS_LOB.getlength (l_blob));
HTP.p( 'Content-Disposition: filename="' || p_file || '"' );
OWA_UTIL.http_header_close;
WPG_DOCLOAD.download_file (l_blob);
DBMS_LOB.freetemporary (l_blob);
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
/I have read that "patch number 8548651" need to be applied in order to download multiple files in Single Page. Is it true? Pls refer this page :
http://dgielis.blogspot.com/2010/01/oracle-application-express-patch-set.html
8555172 -- BLOB download links are incorrect when multiple file items referenced on a page. -
Mulitple File Downloads in AIR
** EDIT **
Just tested. I was throttling the downloads to 28kbps. Think
there must be a timeout on the file functions, as when it was reset
without throttling, the file downloaded 100%. Is there a way to
reset/remove a timeout on a URLStream?
Good morning all.
I'm having trouble with a file download component I've
written. It worked fine debugging, but when testing an installed
version of the application, there seems to be a problem with the
loop, and files not completely downloading.
I have tested, and one file in the loop is writing to the
directory (event.complete action) at about 45%.
How can I check if the total bytes downloaded is the same as
total available, and if not, force it to carry on the download for
that particular item?
The code for the page is below:
public function Update():void {
if(appModel.fileArrCol.length > 0) {
var urlReq:URLRequest = new
URLRequest(appModel.fileArrCol[0][1].toString());
trace(urlReq.url);
urlStream = new URLStream();
urlStream.addEventListener(IOErrorEvent.IO_ERROR,
onStreamError);
urlStream.addEventListener(ProgressEvent.PROGRESS,
progressHandler);
urlStream.addEventListener(Event.COMPLETE,
fileTransferHandler);
urlStream.load(urlReq);
private function fileTransferHandler(event:Event):void {
urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);
var fileLoc:String = appModel.fileArrCol[0][2].toString() +
appModel.fileArrCol[0][0].toString();
var file:File =
File.applicationStorageDirectory.resolvePath(fileLoc);
var fileStream:FileStream = new FileStream();
fileStream.addEventListener(Event.CLOSE, fileClosed);
fileStream.addEventListener(IOErrorEvent.IO_ERROR,
onStreamError);
fileStream.openAsync(file, FileMode.WRITE);
fileStream.writeBytes(fileData, 0, fileData.length);
fileStream.close();
trace("File " + appModel.fileArrCol.length + ": " +
appModel.fileArrCol[0][0].toString());
private function onStreamError(event:IOErrorEvent):void{
//Alert.show("Invalid Username or Password!","Warning");
this.showCloseButton =true;
btnUpdate.visible = true;
trace(event.text);
private function progressHandler(event:ProgressEvent):void {
/* bar.setProgress( Number(event.bytesLoaded /
event.bytesTotal), 1 ); */
bar.setProgress(event.bytesLoaded,event.bytesTotal);
progLabel.text = "Downloading " +
Math.round(event.bytesLoaded / 1024) + " kb of " +
Math.round(event.bytesTotal / 1024) + " kb " +
(appModel.fileArr.length - 1) + " files remaining";
private function fileClosed(event:Event):void {
// run a progress bar or sqlite table update here
appModel.fileArrCol.removeItemAt(0);
if (appModel.fileArrCol.length > 0){
Update();
} else {
progLabel.text = "Uploads Complete";
var thisServerVersion:String =
appModel.fileDownloadServerVersion;
var thisDescription:String =
appModel.fileDownloadDescription;
var thisDownloadDate:String = appModel.fileDownloadDate;
// store the file download details within the database table
if(appModel.checkFileDownloadHistory(thisServerVersion).valueOf()
> 0) {
// a record matches the version number in the xml. do
nothing
} else {
appModel.storeFileDownloadHistory(thisServerVersion,thisDescription,thisDownloadDate);
// close the box down
PopUpManager.removePopUp(this)
public function init():void{
btnUpdate.visible = false;
this.showCloseButton = true;
if (appModel.urlAvailable){
Update();
}else{
Alert.show("No Network Connection Detected","Message");
this.showCloseButton =true;
btnUpdate.visible = true;
public function titleWindow_close(evt:CloseEvent):void {
PopUpManager.removePopUp(this)
The application reads the number of files from an xml file on
the server. That works fine, but I think the loop is wrong. In
debug, it traces the file names without a problem
Please please please can someone help me? I need to get this
sorted and resolved by this lunchtime.
Many thanks in advance,
Matthttp://kb.mozillazine.org/Unable_to_save_or_download_files
Separate Issue;
Your System Details shows;
Installed Plug-ins
Shockwave Flash 16.0 r0
Shockwave Flash 11.9 r900
Having more than one version of a program may cause issues.
Grab the uninstaller from here:
'''[http://helpx.adobe.com/flash-player/kb/uninstall-flash-player-windows.html Uninstall Flash Player | Windows]'''
'''[http://helpx.adobe.com/flash-player/kb/uninstall-flash-player-mac-os.html Uninstall Flash Player | Mac]'''
Then reinstall the latest version.
Flash Player '''v16.0.0.257<br>https://www.adobe.com/products/flashplayer/distribution3.html'''
Shockwave Director '''v12.1.6.156 http://get.adobe.com/shockwave/''' -
Creating a file download link on jsp
I have the following on my jsp. The code worked fine until I tried to use it in a new html design page.
<code>
//page name is index.jsp
try //DISPLAY THE CONTENTS OF THE DATA DIRECTORY
File dirname = new File(PATH); // create an instance of the File class
if (dirname.exists()&&dirname.isDirectory())//check to see if File class dirname exists and is valid
String [] allfiles = dirname.list();//create an array of files in the dirname File class
for (int i=0; i< allfiles.length; i+=2)//loop through allfiles[] and print out file links
out.println("<br><table border='1' cellspacing='1' width='99%'>");
out.println("<tr><td width='50%' class='pageFont'><input type='checkbox' name='cb' value='"+allfiles[i]+"'>"+allfiles[i]+" ");
%>
<a class="a" href="index.jsp?downfile=C:\\data\\<%=allfiles[i+1]%>">DOWNLOAD</a></td>
<% if(i+1 < allfiles.length)//PRINTS OUT THE SECOND TD SO THAT WE HAVE 2 COLUMNS OF LINKS
out.println("<td width='50%' class='pageFont'><input type='checkbox' name='cb' value='"+allfiles[i+1]+"'>"+allfiles[i+1]+" ");
%>
<a class="a" href="index.jsp?downfile=C:\\data\\<%=allfiles[i+1]%>">DOWNLOAD</a></td></tr>
<%
out.println("</form></font></table>");
catch (IOException excep)
out.println("An IO exception has occured.");
</code>
Then when clicked this code is run:
<code>
try{
//CHECK TO SEE IF THE FILE HAS BEEN CLICKED TO DOWNLOAD SINGLE FILE
if (request.getParameter("downfile") != null)
String filePath = request.getParameter("downfile");
File f = new File(filePath);//CREATE AN INSTANCE OF THE FILE CLASS AND POINT IT TO THE LOCATION OF THE DIRECTORY CONTAINING THE FILES
if (f.exists() && f.canRead())
response.setContentType ("application/octet-stream");
response.setHeader ("Content-Disposition", "attachment;filename=\""+f.getName()+"\"");
response.setContentLength((int) f.length());
BufferedInputStream fileInputStream = new BufferedInputStream(new FileInputStream(f));
int i;
out.clearBuffer();
while ((i = fileInputStream.read()) != -1) out.write(i);
fileInputStream.close();
out.flush();
</code>
When I click on this link I get the download dialog box. If I open it I get the following open up in notepad(the files I am trying to give download links are .txt files)
Below is what is displayed in notepad ALL on 1 line:
<html>
<head>
<LINK rel="stylesheet" ty
That is displayed in all of the links that I click on. It is the first few lines of html code for index.jsp.
I know this code is probably not a good way of doing what I need but I got it to work fine until the change.
I am sure there is an easier way to code the download link without resubmitting the page.
Thanks in advance!!Well all was fine with this jsp until I moved it to ApacheJServ. Now the problem has resurfaced(although it is a little different now)
I had moved the following code to the top of my page:
//CHECK TO SEE IF EITHER DOWNFILE OR ZIPFILE VARIABLE EXIST, AND IF THEY DO SET CONTENT TYPE BEFORE SENDING ANY HTML CODE TO THE BROWSER
try{
//CHECK TO SEE IF THE FILE HAS BEEN CLICKED TO DOWNLOAD SINGLE FILE
if (request.getParameter("downfile") != null)
String filePath = request.getParameter("downfile");
File f = new File(filePath);//CREATE AN INSTANCE OF THE FILE CLASS AND POINT IT TO THE LOCATION OF THE DIRECTORY CONTAINING THE FILES
if (f.exists() && f.canRead())
response.setContentType ("application/octet-stream");
response.setHeader ("Content-Disposition", "attachment;filename=\""+f.getName()+"\"");
response.setContentLength((int) f.length());
BufferedInputStream fileInputStream = new BufferedInputStream(new FileInputStream(f));
int i;
out.clearBuffer();
while ((i = fileInputStream.read()) != -1) out.write(i);
fileInputStream.close();
out.flush();
response.flushBuffer();
catch (Exception e){}
//This is where the java code ends and the javascript/html code begins.Then further into the page I create the file download links like so:
<a class="a" href="main.jsp?downfile=C:\\data\\<%=allfiles[i+1]%>">DOWNLOAD</a>I know this isnt a secure way of doing this but I am on a intranet.
The problem I am having now is that when I click on one of the links and download the file and then open it, I get the contents of the file plus concatenated to the end of it is the first few HTML lines of the actual jsp that I downloaded the file from. Before I was just getting the first few lines of html from the jsp, not the actual contents of the downloaded file.
This is an example of what I am getting:
This is the contents of the file that I downloaded.//This is where the file contents ends.
<html>
<head>
<LINK rel="stylesheet" type="text/css" href="default.css">
<script language="JavaScript1.2">
//function that allows user to select all checkboxes
function doIt(v)
for(var i=0;i<document.form1.cb.length;i++)
document.form1.cb.checked=eval(v);
function swap(imageName,image)
imageName.src = "templateImages/"+image;
function imageOver(imageSrc, imageName)
changeImage = new Image();
changeImage.src = imageSrc;
document.images[imageName].src = changeImage.src;
var hide = true;
function hideShow( ) /
Any morre ideas?
TIA!
BTW, I went to ApacheJServ because they wont let me use tomcat :( -
Error while opening PDF file downloaded from database Blob column
Hi All,
I am working on jdev 11.1.1.4.0.
In my use-case I am using filedownload Actionlistner on a link to get the PDF file stored in the database in blob field. These files are being uploaded from other use-case in adf only.
After getting the dialog box to open/save/cancel for the PDF file when i click on open then i am getting an error *'Adobe Reader could not open 'abc.pdf' because it is either not a supported file type*
or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly docoded)' for some files , and to my surprise I am able to open some files.
When I open these PDF files separately from desktop I am able to view the content of each and every file in adobe reader.
I dont know where the problem exactly lies , while uploading/downloading the file . Any ideas/thoughts to resolve this issue?
Thanks
KanikaThanks a lot Timo...!!!
I checked the PDF file downloaded directly from the blob column in DB, there only it is corrupted so must be the problem in uploading the file. I am checking the code line by line,, but no problem in setting the file content type,size etc.
Here is the code snippet ..
byte[] buff;
buff = new byte[(int)length]; -- Length is the file size
int bytesRead = is.read(buff);
for (int i = 0; bytesRead < buff.length; i++) {
// int b = is.read();
int b = is.read();
if (b == -1)
break;
buff[i] = (byte)b;
BlobDomain blobDomian = new BlobDomain((buff));
TestVORow = (TestVORow Impl)TestVO.createRow();
if(blobDomian != null) {
TestVORow.setAttachment(blobDomian);
am.getTransaction().commit();
This seems to be Ok to me..the same issue, file is still corrupting.
Any thoughts from your side ???
Thanks
Kanika
The problem is resolved.
Changes made are instead of
InputStream is;
used ... BufferedInputStream bis ;
and after
for (int i = 0; bytesRead < buff.length; i++) {
// int b = bis.read();
int b = bis.read();
if (b == -1)
break;
buff[i] = (byte)b;
bis.close(); // use this close bufferedInput Stream.
Able to open each and every file now..Thanks for your suggestions Timo and Frank.
Edited by: Kanika on Mar 6, 2012 3:15 AM -
I have a credit in my itunes account, but when I click on "redeem" it asks me to enter a gift card or download code. what are the steps to go in and be able to redeem the credit I have? If I go to an album that I want to use my credit on, the only choice I am seeing is to use the credit card on file. Help!
It says at the top under Redeem after I touched that:
$14.73
Account: [email protected] (my account name)
Enter your Gift Card or Download Coad -
In some thread, i had this problem with file download that instead of opening File Save..popup, the contents of file on the server were being rendered statically as HTML. I have figured out the solution to that but now the thing is in every file, there are some \n\r being added in the beginning of the file. Can anybody help. Here's is my code.
<%@ page import="java.io.*"%>
<%
try
response.setContentType("APPLICATION/OCTET-STREAM");
String strProjectInfoPageHeader = "Attachment;Filename=\"" + request.getParameter("txtProjectInfoPageFileName") + "\"";
response.setHeader("Content-Disposition", strProjectInfoPageHeader);
File fileToDownloadProjectInfoPage = new File(request.getParameter("txtProjectInfoPageFilePath"));
FileInputStream fileInputStreamProjectInfoPage = new FileInputStream(fileToDownloadProjectInfoPage);
int varProjectInfoPage;
while ( (varProjectInfoPage=fileInputStreamProjectInfoPage.read()) != -1 )
out.write(varProjectInfoPage);
out.flush();
out.close();
fileInputStreamProjectInfoPage.close();
catch(Exception e)
out.println(e);
%>Thanks and regards
VikramJSPs will invariably have newlines and whitespace in them, even if you don't explicitly put them. Instead of wasting time trying to fix it, just move your code to a servlet and map it to the same path. That's the fastest and most sensible solution. It also follows the convention that JSPs are to be used for display only and servlets for processing.
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://www.catb.org/~esr/faqs/smart-questions.html
----------------------------------------------------------------
Maybe you are looking for
-
Boa noite! Fiz uma compra de uma Go Pro no Best Buy e necessito da 2ª via da nota fiscal, tenho todos os dados para a obter a mesma. Já enviei 3 vezes os dados para Karina e até agora não obtive resposta. Aguardo resposta o mais breve possível.
-
Error message when importing photos from iPhoto
I have been trying to import pictures from iPhoto and when I try to set the duration to about 7 seconds with 240 photos, it says ERROR DURING IMPORT The file could not be imported: There is not enough disk space left to import Macintosh HD/Users/....
-
Why does NetFlix not play on Apple TV when I click on the feature I want to watch? Why does it alway come up as an error, not loading, try later?
-
Get subset of date from a view
I need to get 100 rows each time from a view which has about 2000 rows, i.e. get row 101 to 200 at one time, then 201 to 300 next time, and so on, we had a SQL statements doing this, but when the number getting larger (smaller number worked)I got a O
-
Urgent, Restricting Sales org & Distribution Channel
I'm having two users and one is from US and other MEXICO If user from US LOG'S into SAP ,He should only his Sales org(US01) & Distribution Channel(001) & Mexico User log ,then he should be able to see only his Sales org(ME01). My Question is there a