Urgent: File download using HTTP

Hello,
I have some files stored on a Remote machine A. The machine A accepts HTTP connection only.
I want to write a java program which runs on Machine B, creates a connection to machine A and gets/downloads the file and store it on machine B. The file is a 3gp/mp4 file.
Can you please advise/suggest as how this can be done?
Regards.

Thanks for your reply.
I am getting the following error now, can some one please advise how to fix this:
HttpTest.java:12: incompatible types
found : java.net.URLConnection
required: java.net.HttpURLConnection
(The openConnection method returns a URLConnection object and not a HttpURLConnection object)
I also tried the below code:
URL url = new URL("http","10.176.96.63",9000,"c:\\database.properties");
InputStream is = url.openStream();
This code gives an exception:
java.net.SocketException: Unexpected end of file from server
Can someone please help...
Thanks.

Similar Messages

  • Accessing BSP File Download using HTTPS URL

    Hi,
    I'm struggling with a problem of downloading a file from a https url. I wrote a BSP App for downloading a file from a unix server.. It works fine when I use a http URL with port 8080 and does not work when I use https.!!
    Example:
    https://comms.gmsanet.co.za/supplier [ download does not work ]
    http://comms.gmsanet.co.za:8080/supplier [ download works ]
    When I try to download using https.. it does not pull the file name and path
    see code  below and suggest me if anything to be chnaged.
    In the Form Initialization method:
    event handler fr data retrieval
    DATA: i_file        type string,
          s_fields      TYPE tihttpnvp,
          s_fields_line TYPE ihttpnvp,
          multipart_form type ref to if_http_entity,
          file_upload    type xstring,
          lv_backend     type string,
          success        type string,
          entity         type ref to if_http_entity,
          file           type xstring,
          content_type   type string,
          content_filename type string,
          content_length type string,
          content_disposition type string,
          num_multiparts type i,
          i              type i value 1,
          doEcho         type string value 'X',
          value          type string,
          filename       type ZFILETAB-fileinfo,
          ext1           type string,
          ext2           type string,
          dsn            type string,
          bptype         like sy-uname,
          itab           TYPE ZFILETAB,
          itab_line      TYPE ZFILETABLINE,
          file_ext       type ZFILETABLINE,
          fileinfo       type c,
          zcount         type i.
        filename = '/NewMessge.doc'.
        content_filename = filename.
    Check the extension and assign the content type
        split filename at '.' into ext1 ext2.
        case ext2.
          when 'zip'.
            content_type = 'application/x-zip-compressed'.
          when 'doc'.
            content_type = 'application/msword'.
          when 'txt'.
            content_type = 'text/plain'.
          when 'ppt' or 'pps'.
            content_type = 'application/vnd.ms-powerpoint'.
          when 'xls' or 'exe'.
            content_type = 'application/octet-stream'.
          when 'gif'.
            content_type = 'image/gif'.
          when 'jpg' or 'jpeg'.
            content_type = 'image/pjpeg'.
          when 'htm' or 'html'.
            content_type = 'text/html'.
        endcase.
        dsn = filename.
        OPEN DATASET dsn FOR INPUT IN BINARY MODE.
        IF sy-subrc NE 0.
          zmessage = 'Error opening file'.
          navigation->set_parameter( name = 'zmessage' value = zmessage ).
          navigation->goto_page( 'downloaderror.htm' ).
          exit.
        ENDIF.
        DO.
          READ DATASET dsn INTO <b>file</b>.
          EXIT.
        ENDDO.
        CLOSE DATASET dsn.
    set response data to be the file content
      runtime->server->response->set_data( <b>file</b> ).
      runtime->server->response->set_header_field(
                                    name  = 'Content-Type'
                                    value = content_type ).
      concatenate 'attachment; filename=' filename into content_disposition.
      runtime->server->response->set_header_field(
                                    name = 'Content-Disposition'
                                    value = content_disposition ).
    set the file size in the response
      content_length = xstrlen( file ).
      runtime->server->response->set_header_field(
                                name  = 'Content-Length'
                                value = content_length ).
      runtime->server->response->delete_header_field(
                                name = 'Cache-Control' ).
      runtime->server->response->delete_header_field(
                                name = 'Expires' ).
      navigation->response_complete( ).
    Thanks
    Ajay

    Hi Brian,
    I have the same problem as Ajay Yeluguri. In http mode I can generate a download of an Excel document but when we use the portal in https it doesn't work.
    When I try to download using https it does not pull the file name and path and when I choose download I have a error message : "Internet Explorer cannot download from ..."
    I've test the point 3.2 "... including file up/download" of the BSP application IT00 and it works fine in http and https mode. My problem is not the upload but the download. And in this application the uploaded document is opened in the Internet Explorer window but I want to generate a Save as... window to download the file.
    Have you an idea what i can do to solve my problem.
    Thanks
    Yann

  • Mangled file downloads over http problem in 10g

    I have a web app running in an OC4J stand alone 10.1.3.3 and am having a problem with downloading files over http. Its a struts2 app whose file downloading impl is easy to use and standard code for writing to an http servlet response output stream.
    Using the firefox plugin for Live Headers I can see that the headers are correctly added to the servlet response and I do get the file I want. However the file has been mangled with binary output around the text. This is the case for txt, word, or any other file.
    This problem does not occur in Jetty or Tomcat. I've also ruled out file corruption while going in/out of the database since I can upload a file when running oc4j, turn off oc4j, start up my app in Jetty and retrieve the same file just fine.
    The mime types are all accounted for and the problem exists regardless if I use a specific content type or just application/download. My browsers (firefox and ie) also recognize all files from the content disposition value "attachment; filename=myfilename.ext". Its just the file content that some how has been wrecked on the way out of the container.
    Has anyone experienced this? I only found one or two unanswered posts elsewhere.
    How can this be mitigated?
    Thanks in advance.
    Andrew

    Figured it out when I realized it was in fact the data coming from the database that was corrupt. There were some older posts on the hibernate website that pointed to a single property that needs to go in the hibernate.properties file: hibernate.jdbc.use_streams_for_binary=true. Without it, Oracle returns the Blob locator consistently 86 bytes in length and therefore bad binary.

  • Jar file downloaded using FTP gets damaged

    Hi people, Am working on a solution that implements an auto update of an application developed using Java. I am using Apache commons package for downloading the updated JAR file from an FTP site. Once I have the new JAR file on my local machine, I double click it and I get the following error. Invalid or corrupt jarfile C:\FIDS\FIDS.jar When I use a different FTP client to download my JAR file, the file works well when double clicked. What could be happening on my JAR file. Thanks and regards.

    tdulce_aboo wrote:
    I know that FTP is not the best solution, however, sometimes we are bound by what the client has in place.I know, it wasn't trying to attack you, it was just a general rant. FTP is so common and when it's the only thing available you obviously have to use it. I just don't understand those who actively enable it on their server and suggest (or even require) its use.
    What is your suggestion,that I use http? or ?That depends on what it's used for.
    My normal one-stop replacement would be SFTP: based on SSH, secure, authenticated, tunnelable, uses a single connection, doesn't do stupid "translations" of the transfered data, ...

  • File upload using http-post in OSB

    Hi All,
    I am trying to upload a file using http-post method in OSB.
    I have created a business service pointing to the service url, with http method post.
    and calling this business service from a proxy service.
    I am unable to send the form data to the business service.
    Please let me know how to send trhe form data and the file information.
    The error given by Business Service is-
    the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is text/plain
    Thanks in advance.
    Seemant
    Edited by: Seemant Srivastava on Oct 12, 2010 12:28 PM

    Hi Anuj,
    A sample HTML form code for. Post HTTP service-
    <html>
    <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>CSV File</title>
    </head>
    <body>
    <form method="post" enctype="multipart/form-data" action="http://xyz/UploadFile">
    <table>
    <tr>
    <td> Feed id </td>
    <td><input type="text" name="refid" value="" size="20"></td>
    </tr>
    <tr>
    <td> Username (optional)</td>
    <td><input type="text" name="username" value="" size="20"></td>
    </tr>
    <tr>
    <td> Password (optional)</td>
    <td><input type="password" name="password" value="" size="20"></td>
    </tr>
    <tr><td> Select CSV File </td>
    <td> <input type="file" name="upload" value="" width="30"/></td>
    </tr>
    <tr>
    <td><input type="submit" name="Ok" value="Go"> <input type="reset" name="reset" value="Reset"> </td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    I need to pass all these information to OSB business service.

  • Cannot open pdf files downloaded using firefox. They open fine using safari, and used to open fine before my latest update of firefox.????

    I am running the latest version of snow leopard on my mac. Since the last update of Firefox, I have not been able to open any newly downloaded pdf's. I get a message that says "The file cannot be opened.
    it may be damaged or use a file format that preview doesn't recognize."
    When I download using Safari, everything works fine. I have been using Firefox for a long time and all of my bookmarks are in Firefox.

    I also disabled adobe npapi plug-in and now the pdf files open as usual.

  • Anybody have a resolution for PRIAMOS file download using a Mac OSX 10.6.8 and Adobe Reader XI?

    Does anyone have experience of the EU PRIAMOS file download system? I am experiencing difficulties in downloading files in Adobe Reader format ( I have set the default PDF reader to Adobe Reader).
    The PRIAMOS system can only communicate with Windows 32bit - Mozilla Firefox 2 and higher or......
    IE 6 or 7
    IE 7 or 8 (in compatibility mode)
    Supported PDF programmes are:
    Adobe Reader 8.1 or higher
    My Adobe Reader software is the latest version (Adobe Reader XI for Mac with latest update as at 10 Sept 2013)
    The PRIAMOS system does not officially support Mac computers, but PRIAMOS has been used successfully with OS X version 10.5.8 (Leopard) and Mozilla Firefox (2.5) (with built in PDF reader disabled and Adobe Reader enabled) and Adobe Reader 8.1
    Any help would be gratefully appreciated

    Oops, I hit return before I was finished!
    In short, does anyone have any ideas apart from those I've tried. One solution seems to be to go back to 10.6.4 - one of the other discussions seem to indicate that the probelm comes in with 10.6.8.
    Thanks!

  • File download using weblogic 6.1(Urgent)

    Hi all,
    Iam using weblogic 6.1 and wrote a code to download a file.
    Previously when i used the same code , it worked properly in Tomcat but in weblogic it returns some junck values .
    the same code is,
    <%@page import="java.io.*,com.oreilly.servlet.*,javax.servlet.*;"%>
    <%
    ServletOutputStream outs = response.getOutputStream();
    // Get the file to view
    String file = "c:/ww-ww.xls";
    // No file, nothing to view
    if (file == null) {
    out.println("No file to view");
    return;
    // Get and set the type of the file
         response.setContentType("application/vnd.ms-excel");
    // Return the file
    try {
    ServletUtils.returnFile(file, outs);
    catch (FileNotFoundException e) {
    out.println("File not found");
    catch (IOException e) {
    out.println("Problem sending file: " + e.getMessage());
    %>
    can anyone say whats the prob .
    Thanx all

    have u checked with the content type of weblogic.
    as u r getting some chunks that means file has been send but been able
    to display on client side.
    problem must be with content type.

  • File download using jsp

    I am trying to download a file from the server using jsp but it always shows the file in the browser.I want a Save/Open dialog box to allow the user to save this file in the local system. any feedback is welcome.
    thanks in advance
    vinod

    Basically out frame work is in struts.........
    In struts for file down load I wrote the code as
    String fileName = <file name>;
    String filePath = <file path>;
    String fileType = fileName.substring(dotIndex+1,fileName.length());
    ServletOutputStream out = httpservletresponse.getOutputStream();
    if (fileType.trim().equalsIgnoreCase("doc"))
    httpservletresponse.setContentType( "application/msword" );
    else if (fileType.trim().equalsIgnoreCase("xls"))
    httpservletresponse.setContentType( "application/vnd.ms-excel" );
    else if (fileType.trim().equalsIgnoreCase("pdf"))
    httpservletresponse.setContentType( "application/pdf" );
    else if (fileType.trim().equalsIgnoreCase("ppt"))
    httpservletresponse.setContentType( "application/ppt" );
    else
    httpservletresponse.setContentType( "application/octet-stream" );
    httpservletresponse.setHeader("Content-disposition", "attachment; filename=" +actualName );
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filePath));
    BufferedOutputStream bos = new BufferedOutputStream(out);
    byte[] buff = new byte[2048];
    int bytesRead;
    while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
    bos.write(buff, 0, bytesRead);
    I hav written this in seperate function which returns boolean true If this works correctly otherwise fase.
    If it is 'true ' I am forwarding it to 'success.jsp' else'fail.jsp'....................
    Now problem is It is not forwarding to any other pages and giving error as "Illegal state .can not forward.Response already committed."
    I think this error is coming becos of 'response.setHeader()' and using out object.........
    Please give me any solution for this problem.........Since I am strucked here.It is urgent for me to do...................................
    I don't mind If u giv any alteernative code for this..............
    Thanx in advance..................
    Plz. respond quickly...................

  • Extremely urgent-file download issue

    My problem is I hava tabular form with ATTACHMENTS(Select List), ID, Report_Name(linked to download the file). Report_Name has attribute to direct to the URL #OWNER#.download_my_file?p_file=#ID#&p_id=#ATTACHMENTS#
    ATTACHMENTS returns (1,2,3,4,5,6) respectively. Even If select a report_type and click the report name, the URL that I receive has a null value for p_id. Any ideas why this is happening? Once I click the link I get URL not found because my URL only has <b>download_my_file?p_file=2399328756440204&p_id=</b>.It doesn't have the value for p_id. If I substitute manual values <b>download_my_file?p_file=2399328756440204&p_id=1</b> it is working fine.Any help will be extrememly helpful.
    Here is my download_my_file proc code
    create or replace PROCEDURE "DOWNLOAD_MY_FILE" (p_file in number,p_id in number) AS
    v_id NUMBER:=p_id;
    v_mime VARCHAR2(48);
    v_length NUMBER;
    v_file_name VARCHAR2(2000);
    Lob_loc BLOB;
    BEGIN
    IF v_id = 1 THEN
    SELECT MIME_TYPE, BLOB_CONTENT, name,DBMS_LOB.GETLENGTH(blob_content)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM file_subjects
    WHERE id = p_file;
    END IF;
    IF v_id = 2 THEN
    SELECT MIME_TYPE, SUMMARY_FILE_CONTENT, SUMMARY_NAME,DBMS_LOB.GETLENGTH(SUMMARY_FILE_CONTENT)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM file_subjects
    WHERE id = p_file;
    END IF;
    IF v_id = 3 THEN
    SELECT MIME_TYPE, SCREENER_FILE_CONTENT, SCREENER_NAME,DBMS_LOB.GETLENGTH(SCREENER_FILE_CONTENT)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM file_subjects
    WHERE id = p_file;
    END IF;
    IF v_id = 4 THEN
    SELECT MIME_TYPE, DISCUSSION_GUIDE_FILE_CONTENT, DISCUSSION_GUIDE_NAME,DBMS_LOB.GETLENGTH(DISCUSSION_GUIDE_FILE_CONTENT)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM file_subjects
    WHERE id = p_file;
    END IF;
    IF v_id = 5 THEN
    SELECT MIME_TYPE, BRIEFING_DOCUMENT_FILE_CONTENT, BRIEFING_DOCUMENT_NAME,DBMS_LOB.GETLENGTH(BRIEFING_DOCUMENT_FILE_CONTENT)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM file_subjects
    WHERE id = p_file;
    END IF;
    IF v_id = 6 THEN
    SELECT MIME_TYPE, MR_PLAN_FILE_CONTENT, MR_PLAN_NAME,DBMS_LOB.GETLENGTH(MR_PLAN_FILE_CONTENT)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM file_subjects
    WHERE id = p_file;
    END IF;
    /*IF v_file_name is null THEN
    SELECT MIME_TYPE, BLOB_CONTENT, name,DBMS_LOB.GETLENGTH(blob_content)
    INTO v_mime,lob_loc,v_file_name,v_length
    FROM file_subjects
    WHERE id = p_file;
    END IF;*/
    -- 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 asave as
    htp.p('Content-Disposition: attachment; filename="'||substr(v_file_name,instr(v_file_name,'/')+1)|| '"');
    -- close the headers
    owa_util.http_header_close;
    -- download the BLOB
    wpg_docload.download_file( Lob_loc );
    end download_my_file;
    Edited by: Shaan Venkat on Jul 7, 2009 1:01 PM

    http://forums.oracle.com/forums/search.jspa?objID=f137&q=upload+text+to+table
    Re: File Browse, File Upload
    hope this help you

  • I cannot get the file download using 1.6

    Hi,
    I am using HTMLDB v1.6 and I have followed the example to upload and download files. I was able to get the file upload working but I am getting the page cannot be found error message. I am using a package to implement the page download can I do that? The URL I entered when I set the ID files is
    #OWNER#.JobManagement.Download_Submitted_File?p_file=#ID#.
    The URL Generated when I click on the download link is:
    http://aseera:7777/pls/htmldb/BFAYEZ.JobManagement.Download_Submitted_File?p_file=4.
    Anyone has any idea why the download is not working?
    Thanks,
    Bashar

    Sergio,
    I looked at the log files and I was able to figure out what was wrong. I changed my parameter name to p_job_id for the stored procedure but I used the p_file parameter name from the example. I also switched to use the package instead of the stored procedure and that worked too. The only thing I need to figure out is why the downloaded file name is packagename.ext for the file name.
    Thanks,
    Bashar

  • File download using CURL

    Hi there,
    I'm trying to download the file(s) from external server. The protocol which i'm using is https, to download the file i'm using CURL utility but this utility is not downloading the file. Command which i'm using is
    curl -k -u {user_name}:{password} url/{filename}
    the url will look something like https://filetransfer.abc.com
    I tried to list out the file at least but its not working curl -kl -u {user_name}:{password} {url}
    Can some one please suggest me how to use curl for downloading the files.
    Thanks in advance,

    I've tested it with downloading the latest openssl source from https://www.openssl.org. Can you do the same? that way you'll know your curl is working or not.
    here's the output of my curl downloading the latest source:
    vxlt090101:~ fritshoogland$ curl -o test.tgz -v -# https://www.openssl.org/source/openssl-0.9.8k.tar.gz
    * About to connect() to www.openssl.org port 443 (#0)
    *   Trying 195.30.6.166... connected
    * Connected to www.openssl.org (195.30.6.166) port 443 (#0)
    * successfully set certificate verify locations:
    *   CAfile: /usr/share/curl/curl-ca-bundle.crt
      CApath: none
    * SSLv2, Client hello (1):
    } [data not shown]
    * SSLv3, TLS handshake, Server hello (2):
    { [data not shown]
    * SSLv3, TLS handshake, CERT (11):
    { [data not shown]
    * SSLv3, TLS handshake, Server key exchange (12):
    { [data not shown]
    * SSLv3, TLS handshake, Server finished (14):
    { [data not shown]
    * SSLv3, TLS handshake, Client key exchange (16):
    } [data not shown]
    * SSLv3, TLS change cipher, Client hello (1):
    } [data not shown]
    * SSLv3, TLS handshake, Finished (20):
    } [data not shown]
    * SSLv3, TLS change cipher, Client hello (1):
    { [data not shown]
    * SSLv3, TLS handshake, Finished (20):
    { [data not shown]
    * SSL connection using DHE-RSA-AES256-SHA
    * Server certificate:
    *       subject: /C=GB/OU=Domain Control Validated/O=*.openssl.org/CN=*.openssl.org
    *       start date: 2008-09-12 17:14:11 GMT
    *       expire date: 2011-09-13 17:14:06 GMT
    *       common name: *.openssl.org (matched)
    *       issuer: /C=BE/OU=Domain Validation CA/O=GlobalSign nv-sa/CN=GlobalSign Domain Validation CA
    * SSL certificate verify ok.
    GET /source/openssl-0.9.8k.tar.gz HTTP/1.1
    User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
    Host: www.openssl.org
    Accept: */*
    < HTTP/1.1 200 OK
    < Date: Sun, 19 Jul 2009 10:50:43 GMT
    < Server: Apache/1.3.33 (OpenPKG/2.5)
    < Last-Modified: Wed, 25 Mar 2009 12:21:40 GMT
    < ETag: "f0c99a-3ac7e3-49ca21d4"
    < Accept-Ranges: bytes
    < Content-Length: 3852259
    < Content-Type: application/x-tar
    < Content-Encoding: x-gzip
    <
                                                                               0.0%{ [data not shown]
    ######################################################################## 100.0%* Connection #0 to host www.openssl.org left intact
    * Closing connection #0
    * SSLv3, TLS alert, Client hello (1):
    } [data not shown]

  • File download using servlet and jsp. File Dialog comes twice

    Hi
    I was trying to download a file using servlet. There is a link which calls the servlet. When I click on the link file dialog box comes up. On selecting Open it again shows me the file dialog box. I changed the method from POST to GET and it worked properly.
    My question is why does it work with GET and not with POST. I am aware of the differences between POST and GET but am not able to come to a rational explanation for this behaviour.
    Please if anyone can explain this to me I am going crazy thinking an answer for this.
    Thank you.
    Regards
    Jay

    Hi Jay,
    I also have the same question. Why does it work with GET and not for POST?. If you were able to find the answer please let me know.
    Thank you.
    Regards,
    Aravind

  • Make files downloadable from outside tomcat(web) context

    Hi there,
    I made an application on whicht people can upload word/pdf files.
    I put them in a dir called /opt/customer/2342/ , where 2342 is the customer id.
    The files are stored there, because I don't want people to be able to just download the files by using http://www.blahblah.com/customer/2342
    Now I want to create a servlet or jsp file that is able to make the files downloadable for specific users.
    Of course I can find the files using java.util.File. But I don't have a clue how to make them downloadable from this path. Should it be something with a FileStream... ?? And adding the mime-type?
    Can anybody give me some hints on making files downloadable from a specific dir?
    Thanks in advance.
    Jeroen van Hertum

    here is a servlet that is used to load files that are stored on the file system. The user submits the file path releative to a know file path.
    package common.servlet;
    import java.io.*;
    import java.net.*;
    import javax.naming.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.apache.log4j.Logger;
    public class FileResourceServlet extends HttpServlet
        // -------- Static fields ----------------------------------------------
        // Logger
        private static Logger logger = Logger.getLogger(FileResourceServlet.class.getName());
         * Root context for all JNDI lookups
        private static final String ROOT_CONTEXT = "java:comp/env";
         * JNDI lookup name of the binary path value
        private static final String BINARY_PATH_KEY = "binaryPath";
         * Default in case looking it up from the environment fails
        private static final String DEFAULT_FILE_RESOURCE_PATH = "/home/cp/bin";
        // -------- Fields -----------------------------------------------------
        private String fileResourcePath = null;
        // -------- Methods ----------------------------------------------------
         * Initializes the servlet.
        public void init(ServletConfig config) throws ServletException
            super.init(config);
            try
                //Get Norm's info
                Context initCtx = new InitialContext();
                Context envCtx = (Context)initCtx.lookup(ROOT_CONTEXT);
                fileResourcePath = (String)envCtx.lookup(BINARY_PATH_KEY);         
            catch( Exception e )
                logger.error("Error looking up file resource path, going with " +
                             "default value - " + DEFAULT_FILE_RESOURCE_PATH, e);
                this.fileResourcePath = DEFAULT_FILE_RESOURCE_PATH;
            logger.debug("File Resource Path:" + fileResourcePath );
         * Destroys the servlet.
        public void destroy()
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
        protected void processRequest(HttpServletRequest request,
                                      HttpServletResponse resp)
                                      throws ServletException, IOException
            ServletContext sc = getServletContext();
            String pathInfo = request.getPathInfo();
            logger.debug("Path Info: " + pathInfo);
            if (pathInfo!=null && !pathInfo.startsWith("/")) pathInfo = "/" + pathInfo;
            String filename = fileResourcePath + pathInfo;       
            logger.debug("Binary Filename:" + filename );
            // Get the MIME type of the image
            String mimeType = sc.getMimeType(filename);
            if (mimeType == null)
                //sc.log("Could not get MIME type of " + filename);
                logger.warn("Could not get MIME type of " + filename);
                resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                return;
            // Set content type
            resp.setContentType(mimeType);
            // Set content size
            File file = new File(filename);
            resp.setContentLength((int)file.length());
            // Open the file and output streams
            FileInputStream in = new FileInputStream(file);
            OutputStream out = resp.getOutputStream();
            // Copy the contents of the file to the output stream
            byte[] buf = new byte[2048];
            int count = 0;
            while ((count = in.read(buf)) >= 0)
                out.write(buf, 0, count);
            in.close();
            out.close();
         * Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doGet(HttpServletRequest request,
                             HttpServletResponse response)
                             throws ServletException, IOException
            processRequest(request, response);
         * Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doPost(HttpServletRequest request,
                              HttpServletResponse response)
                              throws ServletException, IOException
            processRequest(request, response);
         * Returns a short description of the servlet.
        public String getServletInfo()
            return "Short description";
    }

  • I need some information about File Download & File Upload

    Hi  All,
    Can any one help me on this, I need some information about File Download & File Upload.
    I read tutorial abt file upload and download but some of methods in tutorial are deprecated so i need clear information abt File upload and Download, if possible Code examples.
    Thanks
    Ragards
    Ravi Golla

    Hi Ravi
    Check out thses links for examples:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71
    /docs/DOC-8661#22 [original link is broken]
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/202a850a-58e0-2910-eeb3-bfc3e081257f
    Otherwise you can simply follow this code for file download
    Use the code like this.
    1) Create the button and bind the action for it.
    2)then write this code in the action.
    3) do not write any thing in the init method.
    try {
    final byte[] content = this.getByteArrayFromResourcePath("C:
    xyz.properties");
    final IWDCachedWebResource resource = WDWebResource.getWebResource(content, WDWebResourceType.UNKNOWN);
    try {
    final IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(resource.getAbsoluteURL(), "WD_Filedownload", false);
    window.open();
    catch(Exception e)
    wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
    5) writr the method getByteArrayFromResourcePath
    //@@begin others
    private byte[] getByteArrayFromResourcePath(String resourcePath)
    throws FileNotFoundException, IOException {
    FileInputStream in = new FileInputStream(new File(resourcePath));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int len;
    byte[] part = new byte[10 * 1024];
    while ((len = in.read(part)) != -1) {
    out.write(part, 0, len);
    in.close();
    return out.toByteArray();
    //end
    Similarly for file upload
    Similarly for upload in to server path also do the same
    IWDAttributeInfo attInfo =
    wdContext.getNodeInfo().getAttribute("upload");
    binaryType =
    (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();
    uploadedName = binaryType.getFileName();
    File filename =new File("
    <server name>
    <folder name>
    "+uploadedName ); );
    try {
    FileOutputStream out = new FileOutputStream(filename);
    out.write(b);
    out.close();
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

Maybe you are looking for