Reg :File upload and download from client machine

hi..
anyone help me the way that how to upload and download word
document file from client machine.. i am using j2eeserver1.4 in linux..
i want upload file from client machine(windows) to server(linux.) please
help me . tell me idea regarding..
i have tried this coding.. but i can transfer txt file. only. when i upload mirosoft word file.. it will open with some ascii values with actual content.
<!-- upload.jsp -->
<%@ page import="java.io.*" %>
<%String contentType = request.getContentType();
String file = "";
String saveFile = "";
FileOutputStream fileOut = null;
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength)
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
try { 
file = new String(dataBytes);
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("/") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
pos = file.indexOf("filename=/" + 1);
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
String folder = "/tmp/uploads/";
fileOut = new FileOutputStream(folder + saveFile);
fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush(); } catch(Exception e) {  out.print(e);
} finally
{  try
{fileOut.close();
}catch(Exception err)
%>
please which package will help me to upload word document file with no errror. send me how can use in ftp.. send me some sample program..
Regards..
New User M.Senthil..

Hi,
Well,i don't know whether if this helps people here are not.
It is always a good practise to do it via Servlet and then download content.
The adavantage of doing this is
1). You may not need to pack the downloadable with the .war which you ultimately genrate which ceratinly help us in terms of faster deployment.
3). You may update the new content just by moving a file to the backup folder.
2).One may definately download the content irrespective to the content/file.
Hope example below helps..
Configurations:
In the above example we are assuming that we placing all downlodable file in D:/webapp/downlodables/ and you have configured the same path as a init param with the name "filePath" in your web.xml.
something like the one below.
<servlet>
    <servlet-name>DownloadServlet</servlet-name>
    <servlet-class>com.DownloadServlet</servlet-class>
    <init-param>
       <param-name>filePath</param-name>
       <param-value>D:/webapp/downlodables/</param-name>
       <!--Could use any backup folder Available on your Server-->
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>DownloadServlet</servlet-name>
    <url-pattern>/downloadFile</url-pattern>
</servlet-mapping>DownloadServlet.java:
==================
package com;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.activation.MimetypesFileTypeMap;
*@Author RaHuL
/**Download Servlet
*  which could be accessed downloadFile?fid=fileName
*  or
*  http://HOST_NAME:APPLN_PORT/ApplnContext/downloadFile?fid=fileName
public class DownloadServlet extends HttpServlet{
  private static String filePath = new String();
  private static boolean dirExists = false;
  public void init(ServletConfig config){
      // Acquiring Backup Folder Part
      filePath = config.getInitParameter("filePath");
      dirExists = new File(filePath).exists();      
  private void processAction(HttpServletRequest request,HttpServletResponse response) throws Exception{
       // Some Authentication Checks depending upon requirements.
       // getting fileName which user is requesting for
       String fileName = request.getParameter("fid");
       //Building the filePath
       StringBuffer  tFile = new StringBuffer();
       tFile.append(filePath);    
       tFile.append("fileName"); 
       boolean exists = new File(tFile.toString()).exists();
       // Checking whether the file Exists or not      
       if(exists){
        FileInputStream input = null;
        BufferedOutputStream output = null; 
        int contentLength = 0;
        try{
            // Getting the Mime-Type
            String contentType = new MimetypesFileTypeMap().getContentType(tFile.toString());          
            input = new FileInputStream(tFile.toString());
            contentLength = input.available();
            response.setContentType(contentType);
            response.setContentLength(contentLength);
            response.setHeader("Content-Disposition","attachment;filename="+fileName);
            output = new BufferedOutputStream(response.getOutputStream());
            while ( contentLength-- > 0 ) {
               output.write(input.read());
             output.flush();
          }catch(IOException e) {
                 System.err.println("Exception Occured:"+e.getMessage());
             System.err.println("Exception Localized Message:"+e.getLocalizedMessage());
          } finally {
               if (output != null) {
                   try {
                      output.close();
                  } catch (IOException ie) {
                      System.err.println("Exception Occured:"+e.getMessage());
                         System.err.println("Exception Localized Message:"+e.getLocalizedMessage());                      
       }else{
         response.sendRedirect("/errorPage.html");
  public void doPost(HttpServletRequest request,HttpServletResponse response) throws Exception{       
        processAction(request,response); 
  public void doGet(HttpServletRequest request,HttpServletResponse response) throws Exception{
        processAction(request,response); 
NOTE: Make sure You include activations.jar in your CLASSPATH b4 trying the code.
therefore,if you have something like above set as your application enviroment in the above disccussed
can be done by just giving a simple hyper link like
<a href="downloadFile?fid=fileName.qxd" target="_blank">Download File</a>REGARDS,
RaHuL

Similar Messages

  • File Upload and Download From Presentation server

    I have a requirement to provide a selection option to user to upload a big file from presentation server.
    Not sure whther we can a upload the entire file at one short from presentation server. PLease provide some sample code to upload a huge file from presentation server and downlaod a file to presentation server.

    Hi,
    Try this code for download----
    TABLES:
      kna1.                                " General Data in Customer Master
    TYPES:
      BEGIN OF type_s_kna1,
        kunnr TYPE kna1-kunnr,             " Customer Number
        adrnr TYPE kna1-adrnr,             " Address
        anred TYPE kna1-anred,             " Title
        erdat TYPE kna1-erdat,             " Date on which record created
        ernam TYPE kna1-ernam,             " Name of Person who Created the
                                           " Object
    END OF type_s_kna1.
    DATA:
      fs_kna1 TYPE type_s_kna1.
    DATA:
        t_kna1 LIKE
      STANDARD TABLE
            OF fs_kna1.
    " Select-options----
    SELECT-OPTIONS:
      s_kunnr FOR kna1-kunnr.              " Customer Number
    AT SELECTION-SCREEN ON s_kunnr.
      SELECT kunnr                         " Customer number
        FROM kna1
        INTO s_kunnr UP TO 1 ROWS.
      ENDSELECT.
      IF sy-subrc NE 0.
        MESSAGE 'No such customer exists' TYPE 'S'.
      ENDIF.                               " IF SY-SUBRC NE 0
    START-OF-SELECTION.
      PERFORM customer_selection.
    FORM customer_selection .
      SELECT kunnr                         " Customer Number
             adrnr                         " Address
             anred                         " Title
             erdat                         " Date of record creation
             ernam                         " Person who created object
        FROM kna1
        INTO TABLE t_kna1
       WHERE kunnr IN s_kunnr.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
        BIN_FILESIZE                  =
          filename                      = 'C:\TEMP\CUSTOMER.TXT'
        FILETYPE                      = 'ASC'
         write_field_separator         = 'X'
        HEADER                        = '00'
        WRITE_LF                      = 'X'
         col_select                    = 'X'
         col_select_mask               = 'XXXXX'
        IGNORE_CERR                   = ABAP_TRUE
        REPLACEMENT                   = '#'
      IMPORTING
        FILELENGTH                    =
        TABLES
          data_tab                      = t_kna1
       EXCEPTIONS
               dataprovider_exception        = 20
         control_flush_error           = 21
         OTHERS                        = 22
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.                               " IF SY-SUBRC NE 0
    ENDFORM.                               " FORM CUSTOMER_SELECTION.
    for upload----
    " Table declarations----
    TABLES:
      bkpf.                                " Accounting Document Header
    TYPES:
      BEGIN OF type_s_bkpf,
        bukrs TYPE bkpf-bukrs,             " Company code
        belnr TYPE bkpf-belnr,             " Accounting Document Number
        gjahr TYPE bkpf-gjahr,             " Fiscal Year
        blart TYPE bkpf-blart,             " Document type
        bldat TYPE bkpf-bldat,             " Document Date in Document
      END OF type_s_bkpf.
    DATA:
      fs_bkpf TYPE type_s_bkpf.
    DATA:
      fname(10) TYPE c VALUE 'ACCOUNTING'  .
    DATA:
        t_bkpf LIKE
      STANDARD TABLE
            OF fs_bkpf.
    *" Select-options----
    SELECT-OPTIONS:
      s_bukrs FOR bkpf-bukrs,              " Company code
      s_gjahr FOR bkpf-gjahr.              " Fiscal year
    OPEN DATASET fname FOR OUTPUT IN BINARY MODE .
    PERFORM account_selection.
    LOOP AT t_bkpf INTO fs_bkpf.
      TRANSFER fs_bkpf TO fname.
    ENDLOOP.                               " LOOP T_BKPF
    CLOSE DATASET fname.
    FORM account_selection .
      SELECT bukrs                         " Company code
             belnr                         " Accounting document number
             gjahr                         " Fiscal year
             blart                         " Document year
             bldat                         " Document date
        FROM bkpf
        INTO TABLE t_bkpf
       WHERE bukrs IN s_bukrs
         AND gjahr IN s_gjahr.
    ENDFORM.                               " FORM ACCOUNT_SELECTION
    also try
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = 'C:\TEMP\CUSTOMER.TXT'
      FILETYPE                      = 'ASC'
       has_field_separator           = 'X'
      HEADER_LENGTH                 = 0
      READ_BY_LINE                  = 'X'
      IGNORE_CERR                   = ABAP_TRUE
      REPLACEMENT                   = '#'
    IMPORTING
      FILELENGTH                    =
      HEADER                        =
      TABLES
        data_tab                      = t_kna1
    EXCEPTIONS
          disk_full                     = 15
       dp_timeout                    = 16
       OTHERS                        = 17
    IF sy-subrc EQ 0.
      PERFORM customer_display.
    ELSE.
      MESSAGE 'No customer file exists'(006) TYPE 'S'.
    ENDIF.                                 " IF SU-SUBRC EQ 0
    Regards,
    jaya
    Edited by: Jayapradha Neeli on May 28, 2009 11:38 AM

  • File Upload and download from a central repositiory.

    Hi experts,
      I  have written the following code in webdynpro for abap...But it is giving error as "Access Via Null Object Not possible"
    This code runs perfectly fine in abap. I dont know what is the problem in webdynpro .
    Code :
       data: ifile1 type RCGFILETR-FTAPPL,
          ifile3 type RCGFILETR-FTAPPL,
          ifile2 type ESEFTAPPL value 'd:\usr\sap\D11\DVEBMGS00\work\TEST1\',   "test5.ppt'.
          filenam type string,
          filenam1 type string,
          filenam2 type string.
    ifile1 = lv_file_name.
    filenam = ifile1.
    ifile3 = ifile1.
    while ifile1 CS '\'.
    split  ifile1 at '\' into filenam1 filenam2.
    ifile1 = filenam2.
    endwhile.
    Concatenate ifile2 filenam2 into ifile2.
    CALL FUNCTION 'C13Z_FILE_UPLOAD_BINARY'
      EXPORTING
        i_file_front_end         = ifile3
        i_file_appl              = ifile2
        I_FILE_OVERWRITE         = 'X'        "ESP1_FALSE
    IMPORTING
      E_FLG_OPEN_ERROR         =
      E_OS_MESSAGE             =
      EXCEPTIONS
        FE_FILE_NOT_EXISTS       = 1
        FE_FILE_READ_ERROR       = 2
        AP_NO_AUTHORITY          = 3
        AP_FILE_OPEN_ERROR       = 4
        AP_FILE_EXISTS           = 5
        OTHERS                   = 6
    IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Pls help me...
    Thanx,
    Pratibha

    Hi Pratibha,
    I don't think you are getting the error due to the code which you have written here. You must have written some code that is causing the error. Put a breakpoint in your code and debug your code.
    Regards
    Arjun

  • File upload and download through web Dynpro2.0.9.

    Hai All,
          File upload and download through web Dynpro "IWDResource" package is used.But in web Dynpro 2.0.9. this package is not possible.How to uplolad and download  files through web Dynpro2.0.9.
          Anyone can help me?
    Thanks in Advance,
    Kindly Regards,
    K.Saravanan.

    Hi Saravanan,
    You can go through these links,
    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/63/9c0e41a346ef6fe10000000a1550b0/frameset.htm">http://help.sap.com/saphelp_nw04/helpdata/en/63/9c0e41a346ef6fe10000000a1550b0/frameset.htm</a>
    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/5a/90ff4cd0c8cd48a69b836e5e550880/frameset.htm">http://help.sap.com/saphelp_nw04/helpdata/en/5a/90ff4cd0c8cd48a69b836e5e550880/frameset.htm</a>
    So, apart from putting FileUpload UI on your view, you have to implement a method which will do the actual uplod for you.
    Hope this helps.
    Regards,
    Mausam

  • How to solve Fusion ADF file upload and download?

    Now we are building web application with Fusion ADF (JDeveloper 11.1.2.0.0). We want to downloading and uploading from tables.Is there any special tool in Fusion ADF or should I going with traditional java coding. Thanks

    Actually ADF Provide Components for file upload and download
    Download :
    <af:fileDownloadActionListener/>
    See tagDoc: http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_fileDownloadActionListener.html
    Upload
    <af:inputFile/>
    See tagDoc: http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_inputFile.html
    Edited by: -CHS on Jul 6, 2011 9:52 AM

  • Using CSA to filter MSN Messenger file upload and download

    How would i go about filtering out the file upload and download functionality in messenger ?
    I've already disallowed the possibility of uploading or saving from Messenger by not allowing the program the read or write files. But when a PC without this policy on it uploads to a CSA protected host. The CSA will download the entire file but then refuse to save the file.
    I'd rather disallow this functionality alltogether ? my guess are that i would hae to do some COM filtering ?
    I'd be greatfull for any hints you might have.
    Best Regards,
    Lasse

    The document Blocking Peer-to-Peer File Sharing Programs with the PIX Firewall has more information on blocking file sharing applications.
    http://www.cisco.com/en/US/tech/tk583/tk372/technologies_tech_note09186a00801e419a.shtml

  • File upload and download through web Dynpro2.0.9. with Java

    Hai All,
          I am working in web Dynpro2.0.9 with Java.For file upload and download "IWDResource" is used.But this package is not available in web Dynpro2.0.9.How to download and upload files through using this version?
          Anyone can help me?
    Thanks in Advance,
    Kindly Regards,
    S.V.Selva Bala.

    Hai Noufal,
        I successfully upload the files to the database.
        For file download i create two views.
       In the first view files are fetched from the database(datatype for the file is image in the database)and it is converted to byte from image.Afterthat the byte is converted to string by using the following code.
    byte source[]=new byte[1024];
                        if(rs.next()){
                             source=rs.getBytes("cv_document_file");
                        String sourcestr=source.toString();
                        wdContext.currentContextElement().setDownloadfile(sourcestr);     
            Now i put the converted string into the second view.In the second view i try to convert the string value into bytes by using the following codes.
    String sourcestr=wdContext.currentContextElement().getDownloadfile();
             byte bs[]=new byte[1024];
             bs=sourcestr.getBytes();
             wdContext.currentDownloadElement().setDownloadfile(bs);
             But it doesn't work and no error.
             Now i am expecting the valuable suggestions from you.
    Thanks in Advance,
    Kind Regards,
    S.V.Selva Bala.

  • Please help me on file upload and download

    Dear all..
    i am new in this i try to apply the tutorial for file upload and download but it is old i work on net weaver 7.1 and many proery has change and i cant applyb this tutorial...

    Thanks. If you can provide some more details about where - some application, or a web page - are you trying to upload or download a file we can discover to documentation you need. Also, it will be of help if you tell what is the name of the outdated guide you mentioned.
    Best regards,
    Rossen

  • The file upload and download

    Hi all,
    I am going to build a form and run on the web. I am going to do a form which intend to do the file upload and download (any type of file). How can I achieve it?
    Also, once I put it on the web, I would like to do a 'web-like' function: when the user click on the file name, it can open it with the association with the browser (For instance, when I click on the *.doc file, it opens the word automatically). Is it poosible to do so and how to do so? Thanks first.
    Patrick

    Go to Utilities>more Utilities>upload/download is there.
    Amresh.

  • Tracking file upload and download details

    Hi All,
    We are using TMG in our place,all users/servers are used to connect the internet with TMG server..
    is there a way to track the information of file upload and download details in TMG.. 
    KJSUBBU

    Hi,
    Please check the blog below. I haven't try it.
    Live monitor for TMG server
    Note: Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee
    the accuracy of this third-party contact information.
    Best Regards,
    Joyce
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Where are the buttons gone File upload and Download in New ABAP Editor

    Where are the buttons gone of File upload and Download in New ABAP Editor in ECC 6.0.
    Or some new utility added for this feature.
    Kindly guide.
    Thanks,
    pradeep

    Go to Utilities>more Utilities>upload/download is there.
    Amresh.

  • File Upload and Download in Oracle iAS PL/SQL Gateway

    i'm using the example 113471.1 to "File Upload and Download in
    Oracle iAS PL/SQL Gateway"
    when i press the submit button after i select a file to upload
    i get the next message in the browser "No se puede mostrar la
    pagina" HTTP 404 file not found.
    I think the problem is in ctnsample.upload_form in the line
    htp.formOpen(curl => 'cntsample.upload', cmethod => 'POST',
    cenctype => 'multipart/form-data');
    The ctnsample.remove work fine.
    Could you,help me...

    There is a document in the Oracle 9iAS 1.0.2.2 Library titled "Using the PL-SQL Gateway" Part Number A90099-01.pdf that explains file upload and download through modplsql. In particular there is a section there titled "Direct BLOB Download" which explains how one can easily download a blob utilising the wpg_docload package.
    I am still concerned that there exist duplicate copies of my blob content. One copy in the wwdoc_document$ table, and one in my custom table.
    Dmitry/Oracle can you confirm this?

  • ANN: Complete File Upload and Download Power For Dreamweaver

    WebAssist is proud to announce the availability of Digital
    File Pro, an
    extension for Dreamweaver that brings complete upload and
    download
    functionality to ASP, ColdFusion and PHP – without
    server-side components.
    Digital File Pro is now available for $79.99 until September
    19, 2006
    (regular price, $99.99). Owners of eCommerce Suite, Super
    Suite or Admin
    Suite from WebAssist can upgrade for only $49.99.
    For more information, visit:
    http://webassist.com/professional/products/productdetails.asp?PID=112&CouponID=0x62xd
    enthusiastically,
    mark haynes
    webassist sales
    Check out our Special Offers at:
    http://www.webassist.com/professional/products/specials.asp

    Mark:
    Were you aware your page
    http://webassist.com/professional/products/productdetails.asp?PID=112&CouponID=0x62xd)
    doesn't render correctly in IE BETA 7 (text cut off on the
    right)?
    Don't know if you knew (or even care since it IS a beta) but
    I thought I'd
    let you know.
    Rick in Tacoma

  • Apex application file -upload and download a file.

    hi
    im having an issue with an application i created,its about uploading and downloading a file in application.the application is working and was able to upload and download a file but i have not idea there the file is stored in the application database,try to search for the file,its something dealing with the apex_application_file and i cant find it.
    Any idea where the file is stored?
    thnx
    nivesh

    Dear nivesh!
    If you upload a file into an APEX application the file is temporarily stored in the APEX_APPLICATION_FILES table. If you close your current application page the APEX_APPLICATION_FILES table will be cleared. You should create your own table to store files in a BLOB column. I've create an example for uploading images into an APEX application on apex.oracle.com. If you want to have a look at it please use the following credentials:
    Workspace: flo_demo
    Username: dev_null
    Password: password
    Application: 61811
    Yours sincerely
    Florian W.

  • File Upload and Download Upto 150MB

    Hi,
    I have a new requirement in application, Where user will be uploading and download file upto 150MB which is the best method to do need a suggestion which will not affect the database performance.
    Need a best way to do in apex to upload and download file.
    Thanks
    Sudhir

    I am also having same problem, my system is restricting the data to 60.1MB while downloading the file. How to solve this. any body have any answer.

Maybe you are looking for