Session making triouble while downloading files successively
hi, i m hving some problems with file downloading.... my code that saves bytes array into the session is as follows
byte[] bytes = proposalService.getDownload(fileName); // a method that returns bytes array
Object bt = request.getSession(false).getAttribute("bytes");
if(bt != null){
request.getSession(false).setAttribute("bytes", null);
request.getSession(false).removeAttribute("bytes");
request.getSession(false).setAttribute("bytes", bytes);
bytes = null;
try {
response.sendRedirect("FileDownload");
} catch (IOException ex) {
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}and the servlet that gets the data from session are able to download
StringBuffer xlsFile = null;
HttpSession session = null;
StringBuffer xlsFileHeader = null;
try {
xlsFile = new StringBuffer();
xlsFile.append("MI_Tariff"+new Date().getTime());
xlsFile.append(".xls");
response.setHeader("Cache-Control", "max-age=30");
response.setContentType("application/xls");
xlsFileHeader = new StringBuffer();
xlsFileHeader.append("attachment; filename="+xlsFile);
response.setHeader("Content-disposition", xlsFileHeader.toString());
session = request.getSession(false);
byte[] bytes = (byte[]) session.getAttribute("bytes");
System.out.println("----------------------------"+bytes.length);
if(bytes !=null && bytes.length > 0) {
response.setContentLength(bytes.length);
ServletOutputStream servletOutputStream = response.getOutputStream();
servletOutputStream.write(bytes, 0, bytes.length);
bytes = null;
} catch(Exception e){
e.printStackTrace();
} finally{
session.setAttribute("bytes",null);
session.removeAttribute("bytes");
xlsFile = null;
xlsFileHeader = null;
}the problem is i m using this code to download 3 files one by one ... some times it returns the proper file that i want to download but sometime last downloaded file is again downloaded....
i debug this code thoroughlly each time new file is fetched and stored in to the session but when the servlet code runs there might be some problems due to which the bytes array remains empty and it returns the last file downloaded....
as u can see bytes are being removed proporly but i think the problem is with session ... it might use diffrent session for retrieving and saving the bytes array.. HOW CAN I SOLVE THIS PROBLEM....
All the suggestions are eagerly welcomed
Thanks in advance
Just realized that I forgot to give the link to the file servlet earlier; take a look at this code:
http://balusc.blogspot.com/2007/07/fileservlet.html
And no, sorry if you thought that was for you personally; I try to put that in every post of mine so that at least some of the new users go and take a look. If you look at most posts on the forums, there are a lot of replies asking the posters to:
- use code tags
- use proper language ( i.e.complete words and not 'u' , 'plz' etc )
- give the problem details clearly
- give stack traces
etc.
Since this resource is already available, I put this up with my posts instead of repeating the same things 50 times a day. It's like a pseudo-signature :)
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
----------------------------------------------------------------
Similar Messages
-
How to create column header text while downloading file
How can we create column header text while downloading file using function GUI_DOWNLOAD(in SAP Release 4.6c) because there is no FIELDNAMES parameter in
4.6c version.Hii,
Check this sample code. I have called GUI_DOWNLOAD twice. Onetime to download header of table and next time data of table
REPORT z_file_download.
DATA: w_name(90) TYPE c.
DATA:
BEGIN OF fs_flight,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
price LIKE sflight-price,
currency LIKE sflight-currency,
END OF fs_flight.
DATA:
BEGIN OF fs_head,
carrid(10) TYPE c,
connid(10) TYPE c,
fldate(10) TYPE c,
price(10) TYPE c,
curr(10) TYPE c,
END OF fs_head.
DATA:
t_head LIKE
TABLE OF
fs_head.
DATA:
t_flight LIKE
TABLE OF
fs_flight.
fs_head-carrid = 'CARRID'.
fs_head-connid = 'CONNID'.
fs_head-fldate = 'FLDATE'.
fs_head-price = 'PRICE'.
fs_head-curr = 'CURRENCY'.
APPEND fs_head TO t_head.
SELECT-OPTIONS:
s_carrid FOR fs_flight-carrid.
START-OF-SELECTION.
SELECT carrid
connid
fldate
price
currency
FROM sflight
INTO TABLE t_flight
WHERE carrid IN s_carrid.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = 'D:\flight.xls'
FILETYPE = 'ASC'
* APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* IMPORTING
* FILELENGTH =
tables
data_tab = t_head
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'D:\flight.xls'
filetype = 'ASC'
append = 'X'
write_field_separator = 'X'
TABLES
data_tab = t_flight
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc EQ 0.
MESSAGE 'Download successful' TYPE 'I'.
ENDIF.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards
Abhijeet -
Error occurred while downloading files from Administration Server...
Hi guys,
If i already have my application deployed and exploded in ../tmp/_WL_user , when I restart the managed server it will try to download again the files from the upload directory in the Administration Servers? (I'm using stage mode).
Sometimes I got the following error:
Caused By: java.io.IOException: [DeploymentService:290066]Error occurred while downloading files from Administration Server for deployment request "0". Underlying error is: "null"
and I already have the war exploded in /tmp/_WL_user
the staging mode is not only for the first deployment? when i don't have the war exploded in /tmp/_WL_user?
I've some confusion related to the process or deployment/startup of the managed servers.
ThanksHi,
when you get following error * DeploymentService:290066 * then that means
A service on the machine is preventing the WebLogic Server remote instance from downloading the configuration file. This can be Hosts Intrusion Prevention (HIPS) agents or any other agent causing this issue.
Disable the agent interfering with the download process to fix this issue.
Regards,
Kal -
Computer slows down while downloading files using Safari version 4.0.3
I experience some performance issues while downloading files from the internet.
The system performance/responsiveness is perfect until starting the download process.
E.g. opening the finder takes noticeably more time.
However, the worst is moving the mouse (bluetooth mighty mouse). It's hard to explain, but during a download there's a lag which could be compared to decreasing the mouse sensitivity to a minimum.
Maybe someone could help me with that...
Thanks a lot!HI and Welcome to Apple Discussions...
Check to see how much free drive space there is on the MacBook.
Right or control click the MacintoshHD icon. Click Get Info. In the Get Info window you will see Capacity and Available. *Make sure you always have a minimum of 10% to 15% free disk space at all times.*
If you need to free up disk space, go here for help.
http://www.thexlab.com/faqs/freeingspace.html
Could be an underlying issue with the hard disk. Boot from your install disk and run Disk Utility.
Insert Installer disk and Restart, holding down the "C" key until grey Apple appears.
Go to Installer menu and launch Disk Utility.
Select your HDD (manufacturer ID) in the left panel.
Select First Aid in the Main panel.
*(Check S.M.A.R.T Status of HDD at the bottom of right panel. It should say: Verified)*
Click Repair Disk on the bottom right.
If DU reports disk does not need repairs quit DU and restart.
If DU reports errors Repair again and again until DU reports disk is repaired.
When you are finished with DU, from the Menu Bar, select Utilities/Startup Manager.
Select your start up disk and click Restart
Carolyn -
While downloading files Firefox 4 freezes (started with 3.5) and sometimes I get a window that says Script: chrome://mozapps/content/downloads/download.xml:68 has stopped responding or is busy and asks if I want to stop script or ignore. I have looked through about:config and don't see a way to disable the script and keep it disabled.
That is a problem with an AVG extension (Tools > Add-ons > Extensions)
See:
* [[Troubleshooting extensions and themes]] -
Error in PDF Conversion while downloading file from application server
Hi,
I am facing a problem in which i have to download file from application server which is a PDF file (output of SAP Script). I am downloading this file using following code in BSP technology:
* event handler for data retrieval
EMPCD = REQUEST->GET_FORM_FIELD( 'emp' ).
MONTH = REQUEST->GET_FORM_FIELD( 'mn' ).
YEAR = REQUEST->GET_FORM_FIELD( 'yr' ).
W_IND = 'N' .
DATA : wa_zform16 type zform16.
DATA : file_path type string.
DATA : l_pdf_len type string.
DATA STR TYPE STRING.
DATA: OUTPUT TYPE STRING ,
L_XSTRING TYPE XSTRING ,
APP_TYPE TYPE STRING.
DATA: PDF_TABLE TYPE RCL_BAG_TLINE.
DATA PHY_NAME_OUT TYPE SAPB-SAPPFAD.
concatenate '/usr/sap/put/form16/' EMPCD '_' YEAR '.PDF' into file_path
*PHY_NAME_OUT = '/usr/sap/put/form16/01000200_2007.PDF'.
PHY_NAME_OUT = file_path.
OPEN DATASET PHY_NAME_OUT FOR INPUT IN TEXT MODE ENCODING default.
IF SY-SUBRC IS INITIAL.
DO.
READ DATASET PHY_NAME_OUT INTO STR.
IF SY-SUBRC IS INITIAL.
CONCATENATE
OUTPUT
STR
CL_ABAP_CHAR_UTILITIES=>CR_LF
INTO OUTPUT.
ELSE.
EXIT.
ENDIF.
ENDDO.
APP_TYPE = 'APPLICATION/PDF'.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = OUTPUT
MIMETYPE = 'APPLICATION/PDF'
* MIMETYPE = 'APPLICATION/PDF;charset=utf-16le'
IMPORTING
BUFFER = L_XSTRING.
CALL METHOD CL_BSP_UTILITY=>DOWNLOAD
EXPORTING
OBJECT_S = L_XSTRING
CONTENT_TYPE = APP_TYPE
CONTENT_DISPOSITION = 'attachment;filename=webforms.pdf'
RESPONSE = _M_RESPONSE
NAVIGATION = NAVIGATION.
Result of this code is : there is a pop up asking to open or save pdf format and process is complete, but i have problem in downloaded file.
At the time of creation i have put BMP image for signature in PDF file and it is working fine but when i upload that file in Application server and then download it with above used code it save the PDF file but when i open that file so whereever i have used signature that page gives error and could not display that scanned signature.
Can anyone please help me in this regard.
or is there any possibility from which i can download that file just like File transfer from BSP.
Keep in mind that i am using BSP technology so all GUI based function module to download file are not working.
waiting for your reply.....
Regards,
GaganHi Raja,
I have standard sap form for TDS Certificate on which i have include an BMP image for digital signature and download that script into pdf format.While i download that PDF looks ok but it is not working in BSP.
Regards,
Gagan -
Error while downloading file with Firefox 33
Hello,
in our company we all use firefox (different versions) to use our CRM (SugarCRM).
Since some of the PC (with windows 7) updated to Firefox version 33 (64bit) we started getting the following problem while downloading PDF:
"C:\Users\[user]\AppData\Local\Temp\[tempfilename].part could not be saved, because the source file could not be read."
We tried to downgrade to Firefox 32 and everything seems to be working fine.
I already tried to delete the profile, reinstall Firefox, clear cache, delete Profile folder, but nothing helped.
Can it be a Firefox 33 bug?
ThanksI tried to change the download folder, no help tehre.
I also tried disabling the Antivirus and Firewall, still the same.
I even tried to boot windows in safe mode, and when I download the file I don't get the error but the file just fails to download.
I just want to underline that if I downgrade to version 32 everything works.
thanks -
Hi all,
I am facing some problem while downloading the data to presentation server.In the program they are using the FM 'WS_DOWNLOAD' to download the file.But its not working and setting the sy-subrc eq 2 which means 'Cannot Write to File'.wat could be the possible reasons?
Thanks..Hi,
That error pops up if you donot have authorizations in creating/writing a file on the presentation server ...and also if the file path that you have given is incorrect......
* download report to file
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = 'C:tempreport.txt'
filetype = 'ASC'
TABLES
data_tab = it_report.
Check whether you have passed the parameters as per this
http://www.sapdevelopment.co.uk/reporting/rep_capturerep.htm
Else please paste your code here -
Japanese character problem while downloading file to application server
Hello All,
We are facing a strange problem while downloading a file to application server when file contains japanese text.
We are downloading vendor and customer information in a flat file format on application server. When the login language is EN program show ouput in a properly formatted manner.
When the login language is JA (japanese) program does download file with customer vendor data. I can see the description is japanese language but the formatting is gone for a toss.
We are facing similar issue with other programs downloading files on the application server.
I am using OPEN DATASET........ENCODING DEFAULT. and working on unicode enabaled ECC 6.0 system
Quick help appriciated.
Thanks!Hi
Sometimes this also happens because of your desktop setting.Make sure that your OS also supports the JAPANESSE language.
Ask your technical support team to enable them in your desktop.
Thanks & Regards
Jyo -
While downloading file to application server its overwriting the earlier fi
hi if i am using below code with date time stamp the file is downloaded to the application server correctly and each time i execut eht program a difference file is generated as date time stamp differs each time but
whne i remove the date time stamp ie sy-datum and sy-uzeit as we dont need to display the date time stamp with the file each time i execute the program a file is generated but it overwrites the ealier existing file please suggest as each time it shoul generate a new file....
Concatenate file name sy-datum sy-uzeit '.txt' into v_datetimefile
file on Appplication Server is selected
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
CLIENT = SY-MANDT
logical_filename = 'ZFILE'Hi,
first of all decide you have to overwrite the existing file or you want to create the new, i think the answer is there in your query itself, if you want to create new then concatenate the date and time, else don't do that.
below are the additions we can use while opening the data set.
FOR INPUT
FOR OUTPUT
FOR APPENDING
IN BINARY MODE
IN TEXT MODE
AT POSITION p
TYPE ctrl
MESSAGE mess
FILTER f
Reward if useful.
Thanks,
Sreeram. -
Problem while downloading file from custom table
Hi All,
Im trying to download the file from the custom table where i have stored the uploaded files through apex.
I have created the download procedure as mentioned in the oracle docs ,
And given the execute grant for public user.
and calling that procedure by calling the URL -- #OWNER#.download_my_file?p_file=#ID#
But im getting the below error
Forbidden
You don't have permission to access /pls/apex/owner.download_my_file on this server.
Oracle-Application-Server-10g/10.1.2.0.2 Oracle-HTTP-Server Server at servername Port number
Can any one tell whats the problem here.
Thanks in advance
regards,
Arumugam KRYour function apex_util.get_blob_file_src under region, the first argument must be the name of page item anywhere in your application that is of type "file browse." So if your form for uploading the blob content is on page 11 and the file browse item is "P11_FILE_NAME" then your query would look like below:
SELECT FILE_ID
, FILE_NAME
, CASE WHEN NVL(dbms_lob.getlength(BLOB_CONTENT),0) = 0
THEN NULL
ELSE
CASE WHEN attach_mimetype like 'image%'
THEN '<img src="'||apex_util.get_blob_file_src('P11_FILE_NAME',id)||'" />'
ELSE
'<a href="'||apex_util.get_blob_file_src('P11_FILE_NAME',id)||'">Download</a>'
end
END new_img
FROM TABLE_NAME
GET_BLOB_FILE_SRC FunctionAs an alternative to using the built-in methods of providing a download link, you can use the APEX_UTIL.GET_BLOB_FILE_SRC function. One advantage of this approach, is the ability to more specifically format the display of the image (with height and width tags). Please note that this approach is only valid if called from a valid Oracle Application Express session. Also, this method requires that the parameters that describe the BLOB to be listed as the format of a valid item within the application. That item is then referenced by the function.>
[url http://docs.oracle.com/cd/E14373_01/apirefs.32/e13369/apex_util.htm]GET_BLOB_FILE_SRC -
Issue while downloading file in .CSV format
Hi,
I need to download the file in .CSV format.
I hade used FM SAP_CONVERT_TO_CSV_FORMAT and then used GUI_Download.
Now when I am opening file which is downloaded, it gives all the data in a single column. If there are 5 fields in my table, the generated file gives the data of all the 5 fields in a single column.
Could you please help?Hi try wi th the following code.
TYPE-POOLS : truxs.
DATA: t_file TYPE STANDARD TABLE OF type_file.
data:t_conv_data TYPE truxs_t_text_data.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
i_field_seperator = ', '
TABLES
i_tab_sap_data = t_file
CHANGING
i_tab_converted_data = t_conv_data
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\TESTCSV.CSV'
filetype = 'ASC'
write_field_separator = ' '
TABLES
data_tab = t_file
fieldnames = names
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22. -
Problem with Dataset While downloading file to Application server
Hi friends,
My report downloading some data to Application server in Unix Environment. When i am seeing that dataset, contents of the last field getting truncated. I specified length of the file which is greater than the record length, but still values are truncated. Its very urgent please send me the solution ASAP.
Thanks & Regrads,
Ramesh.Please provide me a solution
-
Problem while downloading file in FDTA
Hi,
Our customer is generating the payment file payment medium program,
in FDTA transaction, when download the path name and file name was taking automatically.
Now, when try to download, the path name and file name is not taking automatically.
What could be the reason for disappear of filename now?
Thank you,
vidyaHi
This is due to the variant maintenance in OBPM4 transaction for the Payment medium format.
Go to OBPM4 ---> Select your payment medium format ---> Select the variant
In that edit variant screen, under 'Output Control' tab, there is Check box for 'Output to file system'. if you activate that and give the relevant file path, the file will be downloaded automatically to this path when you run FDTA.
Regards
Srini -
Very urgent : Problem in currency field while downloading file from excel.
I downloaded a excel file to my ABAP program.It contains a currency field which has comma in it. When i do operations on the currency field it says unable to interpret the number.Can anybody help me on this.
Message was edited by:
Bharath Srinivas
Message was edited by:
Bharath SrinivasHi,
Try this. In ur excel right click on that column wher u have the currency, go to format cells and there uncheck the box which shows 'Show tousands (,) seperator).That shud solve the problem.
Thanks
Vasudha
Maybe you are looking for
-
Acrobat 7.0 Pro installation on W8.1
I own a new PC with W8.1 after deciding to renew my old and good-working PC with XP. I tried to install my Acrobat 7.0 Pro from the original CD. During installation I've been prompted about PDF Printer is not installed. Later I discovered that it is
-
Ipod mini skips recently downloaded songs
On occasion, my ipod mini will skip over recently downloaded songs. Does anyone know how I can fix this problem or what I'm doing wrong?
-
NetStream (Audio) (MX 2004)
Hi there. Can someone please shed some light on the NetStream function? 1. Does this allow me to stream an audio file from an alternative source rather than compiling it into my flash file? 2. What audio formats support it? 3. I am trying to develop
-
Connecting to WiFi network-bizarre
Hi, I work on a college campus with a protected network. I can connect to the wireless on my laptop, but it's hit or miss on my iPhone. I have to go through some pretty elaborate steps in order for it to work some of the time... First, my iPhone hard
-
Regarding update 1.1.2??
Can anyone please tell me what is new in this update or what should I see different after updating my Iphone??