Download file from URL using ADF (urgent help required)

We have the following requirement:
On clicking a button we need to download the file present at a particular location(we have the URL).
I have written the following in .jspx file :
<af:commandButton  id="btn1" >
                    <af:fileDownloadActionListener contentType="text/plain; charset=utf-8" method="#{bean.getFile}"/>
</af:commandButton>
The corresponding method in bean is :
public void getFile(FacesContext facesContext, OutputStream outputStream) {
HttpServletResponse response = null;
ServletOutputStream ouputStream = null;
currUrl = getFileURL("ID", 281);
response =
(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
try {
ouputStream = response.getOutputStream();
ouputStream.write(this.getFileBytes(), 0,this.getFileBytes().length);
ouputStream.flush();
ouputStream.close();
} catch (IOException ioe) {
System.out.println("IO Exception");
public byte[] getFileBytes() {
URLConnection urlConn = null;
InputStream iStream = null;
URL url;
byte[] buf;
int byteRead;
try {
url= new URL("http://hjhj:34104/test.pdf");
urlConn = url.openConnection();
iStream = urlConn.getInputStream();
buf = new byte[5000000];
byteRead = iStream.read(buf);
if (byteRead > 0) {
System.out.println("Downloaded Successfully.");
return buf;
} catch (FileNotFoundException fnfe) {
System.out.println("File not found Exception");
fnfe.printStackTrace();
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
e.printStackTrace();
} finally {
try {
iStream.close();
} catch (IOException e) {
System.out.println("IO Exception");
e.printStackTrace();
System.out.println("File");
return null;
The file is opening in same window but in some encrypted format. My requirement is to :
1. Have a pop (as in Mozilla or IE) which asks if I want to save the file or open.
2. Depending on that the file should be opened in pdf format and not in browser same window neither in browser tab.

Jdev version : 11.1.2.1.0
in .jspx file : we have a button. On clicking the button file from URL should be downloaded. I have used fileDownloadActionListener in commandButton. Corresponding code :
<af:commandButton  id="btn1" >
                    <af:fileDownloadActionListener contentType="text/plain; charset=utf-8" method="#{bean.getFile}"/>
</af:commandButton>
in bean class : the method corresponding to fileDownloadActionListener is :
public void getFile(FacesContext facesContext, OutputStream outputStream) {
     HttpServletResponse response = null;
     ServletOutputStream ouputStream = null;
     response =(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
     try {
          ouputStream = response.getOutputStream();
          ouputStream.write(this.getFileBytes(), 0,this.getFileBytes().length);
          ouputStream.flush();
          ouputStream.close();
          } catch (IOException ioe) {
               System.out.println("IO Exception");
public byte[] getFileBytes() {
     URLConnection urlConn = null;
     InputStream iStream = null;
     URL url;
     byte[] buf;
     int byteRead;
     try {
          url= new URL("http://hjhj:34104/test");
          urlConn = url.openConnection();
          iStream = urlConn.getInputStream();
          buf = new byte[5000000];
          byteRead = iStream.read(buf);
          if (byteRead > 0) {
               System.out.println("Downloaded Successfully.");
          return buf;   
    } catch (FileNotFoundException fnfe) {
          System.out.println("File not found Exception");
     } catch (Exception e) {
          System.out.println("IO Exception");
The URL given in the code is for a file which can be a PDF file or an EXCEL file.
My requirement is when i click the button:
1. A pop should come (as in Mozilla or IE) which asks if I want to save the file or open.
2. if i click on save file should save in a particular location.
3. if i click on open it should open as PDF/EXCEL format and NOT in browser.
Message was edited by: 1001638

Similar Messages

  • Uploading and downloading files from a web app (Urgent!!)

    Hi everyone:
    I'm developing an application in PL/SQL to upload and download files from an HTML webpage. I congured the document table and the parameters necessary in the DAD of my application.
    when I upload the file using my webpage that file info is automatically uploaded to the doc table. This is as far as I have gotten.
    I need to do the following:
    - Place the uploaded file into a column in another table in my database as part of a text message (think of it as an email message), and delete the file from the doc table (as this is thought to be a temp table that holds the file when uploaded from my webpage)
    - Retreive the file so that it can be downloaded from another web page.
    The file can be a PDF, WORD DOC, etc...
    I now that I can do this with InterMedia but I haven't figured out how :(
    Can anyone please point me to an example or some documentation that can guide me through the process.
    DB VERSION: 8.1.7
    IAS VERSION: 1.0.2.2
    Thanks,
    Carlos Abarca

    The idea was for you to look at the code and get an idea of how to access the BLOB in the document table. IF you look at the procedure
    insert_new_photo( new_description IN VARCHAR2,
    new_location IN VARCHAR,
    new_photo IN VARCHAR2 )
    It shows how to access the blob that is stored in the document table. You can then copy this blob to your own table using the DBMS_LOB package.
    Hope this helps,
    Larry

  • With Firefox 4, I cannot download files from the internet. Please help me !

    I cannot download files from the internet (with Firefox 4). I was able to until this upgrade. I am disappointed.
    The site specifically is www.c64g.com/games.php?q=p

    What buttons do you get to click on with this message? What browser are you using (e.g. Safari, Chrome, Internet Explorer...)

  • Unable to download file from cloud

    Hi,
    I am unable to download file from adobe cloud.can anyone help me out?

    Adobe has more than one file-storage 'cloud.'  What is the URL of the file you are trying to download?

  • Download files from web to client

    Hi,
    I am trying to download txt file from the web and save it on the client using webutil_file_transfer.url_to_client. I am experiencing some problem which is connected to web util and says: The WEBUTIL object group is not available in this Form. WEBUTIL can not work.WebUtil error: oracle.forms.webutil.filetransfer.filetransfer.
    Can somebodey suggest what is the problem or any other solution for downloading files from url and saving them on the client?

    OK guys, i have done everything and web util finally (probably) works fine because i don't receive any error messages. Despite this i still cant download the file on the client machine.
    ps. I don't receive any error message
    here is the sample code , so you can try it if you want and suggest something
    DECLARE
    flag BOOLEAN;
    BEGIN
    flag :=
    webutil_file_transfer.url_to_client
    ('http://igor.pandurski.googlepages.com/CIIT-Molika-2007-WebServicesforInsur.pdf',
    'C:\1\'
    IF flag
    THEN
    MESSAGE ('DONE');
    MESSAGE ('DONE');
    ELSE
    MESSAGE ('NOT DONE');
    MESSAGE ('NOT DONE');
    END IF;
    END;

  • I used to be able to download files from the Harddrive of my Sony Handycam, but now it won't let me import them while going through "log and transfer."  I have tried to update my settings, but this doesn't seem to work.  Any help would be much appreciated

    I used to be able to download files from the Harddrive of my Sony Handycam, but now it won't let me import them while going through "log and transfer."  I have tried to update my settings, but this doesn't seem to work.  Any help would be much appreciated

    Hard Drive:  The Hard Drive is on my camera (Sony Handycam)
    Just needed some info on what is going on with your particular system.
    Knowing the exact camera model will also assist us.
    If this camera is standard AVCHD you should be able to connect with USB to Mac with FCE open and use Log and Transfer without all the fiddling around converting etc.
    What FCE does during ingest is convert files to AIC. (Apple Intermediate Codec)
    FCE cannot read the individual files in the BDMV folder, that's why all the converting is required when you use that method.
    BTW: regards formatting drives/cards/memory on cameras; it is wise to use the actual device to format rather than a computer. This is a prime cause of read/write goof ups with solid state media. This applies to still or video cameras.
    Keeping the COMPLETE card/memory structure in tact is vital for successful transfers.
    Try here for some trouble shooting tips:
    https://discussions.apple.com/message/12682263#12682263
    Al

  • About "Upload and download files from ADF into blob type colum."

    hi
    Using JDeveloper 10.1.3.3.0 I have tried the example available for download from this blog post by Jakub Pawlowski:
    "Upload and download files from ADF into blob type colum."
    at http://kuba.zilp.pl/?id=1
    First a thank you to Jakub for this interesting example.
    I have a question about a PDF file that I uploaded using the example.
    The file has a size of 10445518 bytes.
    After I upload that file, the blob column has a value with a size of 10445516 bytes, 2 bytes less.
    SQL> select file_name, dbms_lob.getlength(stored_file) from blob_table;
    FILE_NAME
    DBMS_LOB.GETLENGTH(STORED_FILE)
    ADF-DeveloperGuide-4GL-B25947_01.pdf
                           10445516If I download that file using the example, it has the same size as the blob value, 10445516 bytes.
    If I open the downloaded file, using Adobe Reader 8.1.1, it first shows this message:
    "The file is damaged but is being repaired."
    After that, there is not problem using the PDF file in Adobe Reader.
    I have tried this with both Internet Explorer 6 and Firefox 2.0.0.11.
    I have also tried this with other (smaller) files, and those upload and download correctly.
    question:
    Why are those 2 bytes lost during upload?
    many thanks
    Jan Vervecken

    Hi!
    I can only post you my code that works for me and as I said I had same problems but can't remember what solved them. My code:
      public void fileUploaded(ValueChangeEvent event)
        FacesContext fc = FacesContext.getCurrentInstance();
        UploadedFile file = (UploadedFile) event.getNewValue();
        if (file != null && file.getLength() > 0)
          // here I have some messages written and a call to the method on AM to save the uploaded file to the DB
      private BlobDomain newBlobDomainForInputStream(InputStream in)
        throws SQLException, IOException
        BlobDomain loBlob = new BlobDomain();
        OutputStream out = loBlob.getBinaryOutputStream();
        writeInputStreamToWriter(in, out);
        in.close();
        out.close();
        return loBlob;
      private static void writeInputStreamToWriter(InputStream in,
                                                   OutputStream out)
        throws IOException
        byte[] buffer = new byte[8192];
        int charsRead = 0;
        while ((charsRead = in.read(buffer, 0, 8192)) != -1)
          out.write(buffer, 0, charsRead);
       * Launch the upload - see fileUploaded() for actual upload handling.
       * @return null navigation event - we stay on this page
      public String UploadButton_action()
        if (this.getMyInputFile().getValue() == null)
          FacesContext context = FacesContext.getCurrentInstance();
          FacesMessage message =
            new FacesMessage(FacesMessage.SEVERITY_WARN, JSFUtils.getStringFromBundle("fileupload.emptyfielderror"),
                             null);
          context.addMessage(this.getMyInputFile().getId(), message);
        return null;
       * Setter for inputFile UI Component.
       * @param inputFile inputFile UI component
      public void setMyInputFile(CoreInputFile inputFile)
        this.myInputFile = inputFile;
       * Getter for inputFile UI Component.
       * @return inputFile UI component
      public CoreInputFile getMyInputFile()
        return myInputFile;
      }fileUploaded is a valueChangeListener on inputFile and UploadButton_action is as the name says the action for upload button.
    Hope this helps. If not, than your problem is probably not the same as mine was, although the message about file corrupted was the same.
    Next thing you can check in this case is if your file exceeds max file upload size. I don't know the exact default value, but if the file is too long I think this upload logic will upload only a part of the file and save it to the DB which can also lead to the same file corrupted error.
    You can set the max upload value in web.xml like this:
    <context-param>
    <!-- Maximum memory per request (in bytes) -->
    <param-name>oracle.adf.view.faces.UPLOAD_MAX_MEMORY</param-name>
    <!-- Use 5000K -->
    <param-value>5120000</param-value>
    </context-param>
    <context-param>
    <!-- Maximum disk space per request (in bytes) -->
    <param-name>oracle.adf.view.faces.UPLOAD_MAX_DISK_SPACE</param-name>
    <!-- Use 10,000K -->
    <param-value>15360000</param-value>
    </context-param>

  • Download files from the URL and store them in the table

    Hello,
    I want to download files from the URL and want to store them in the table.
    Can I do it using sql/pl-sql.
    Please help me on this.
    Thanks,
    Rajendra Yadav

    Never tried it before...
    Is this what you are talking about?
    http://www.oracle-base.com/articles/10g/file-upload-download-procedures-10g.php
    Cheers,
    Manik.

  • [HELP] Download file from FTP server

    hi,
    I want to write a java program that can download and upload files from ftp server. Currently I only manage to upload a file to ftp server but i cant download file from ftp server. Here is the source code that only allow user to upload file. Anyone can give me some guidelines so that my program can download and also upload file? thx.
    import java.io.*;
    import java.net.*;
    public class FTPUpload {
    private static final int CTRLPORT = 21;
    private static Socket ctrlSocket;
    private static PrintWriter ctrlOutput;
    private static BufferedReader ctrlInput;
    private static byte[] localHostAddress;
    public final static String DIR = "C:\\zip\\";
    public static void main(String[] args) {
    try {
    String host = "192.168.1.1";
    String loginName = "testuser";
    String password = "password";
    String dirName = "/home/testuser";
    String fileName = "hello.zip";
    ctrlSocket = new Socket(host, CTRLPORT);
    localHostAddress = ctrlSocket.getLocalAddress().getAddress();
    ctrlOutput = new PrintWriter(ctrlSocket.getOutputStream());
    ctrlInput = new BufferedReader(new InputStreamReader(ctrlSocket.getInputStream()));
    ctrlOutput.println("USER " + loginName);
    ctrlOutput.flush();
    ctrlOutput.println("PASS " + password);
    ctrlOutput.flush();
    ctrlOutput.println("CWD " + dirName);
    ctrlOutput.flush();
    ctrlOutput.println("TYPE I");
    ctrlOutput.flush();
    FileInputStream fis = new FileInputStream(DIR + fileName);
    Socket dataSocket = dataConnection("STOR " + fileName);
    OutputStream outstr = dataSocket.getOutputStream();
    int n;
    byte[] buff = new byte[1024];
    while ((n = fis.read(buff)) > 0) {
    outstr.write(buff,0,n);
    dataSocket.close();
    fis.close();
    ctrlOutput.close();
    ctrlInput.close();
    ctrlSocket.close();
    }catch (Exception e) {
    e.printStackTrace();
    private static Socket dataConnection(String ctrlcmd)
    throws IOException,UnknownHostException {
    String cmd = "PORT ";
    ServerSocket serverDataSocket = new ServerSocket(0,1);
    for (int i=0;i<4;i++) {
    cmd = cmd + (localHostAddress[i] & 0xff) + ",";
    cmd = cmd + (((serverDataSocket.getLocalPort())/256) & 0xff)
    + ","
    + (serverDataSocket.getLocalPort() & 0xff);
    ctrlOutput.println(cmd);
    ctrlOutput.flush();
    ctrlOutput.println(ctrlcmd);
    ctrlOutput.flush();
    Socket dataSocket = serverDataSocket.accept();
    serverDataSocket.close();
    return dataSocket;
    }

    Or just use a java.net.URL("ftp://...) ..., get its input stream, and away you go ...

  • Can LabVIEW download files from the Internet? I know the URLs of the files.

    Can LabVIEW download files from the Internet? I know the URLs of the files.

    Hi bmihura,
    I'm not sure what you what to do - download or open URLs - but I've put together the attached VI.
    I hope it is of some use.
    Charlie Rodway
    Test Design Engineer
    Rolls-Royce Controls and Data Services Ltd
    Attachments:
    WebBrowser.vi ‏21 KB

  • Hi. Having trouble viewing a downloaded file from a site. iPad is telling has not got a app to open file ,but have downloaded so many now and none of them are any help. Tried this on my android phone still nothing. Please can anyone help as slowly ma

    HHi having trouble viewing a downloaded file from a site my iPad is telling me I don have a app to open file . And have downloaded loads of apps and still no joy . Have tried this on my android phone to and still nothing. Please can anyone help as slowly going crazy. Thanks tim

    What type of file?  From what site?  What Apps have you downloaded for it?
    Perhaps if you provide details of what you are doing we can provide more precise help.

  • S my computer will on itunes said that it will not use my new ipod touch because it says that service is not started. I have registered my new ipod touch and am trying to download stuff from my itunelibrary. Ps help!

    my computer will on itunes said that it will not use my new ipod touch because it says that service is not started. I have registered my new ipod touch and am trying to download stuff from my itunelibrary. Ps help!

    Try:
    iPhone, iPad, iPod touch: How to restart the Apple Mobile Device Service (AMDS) on Windows

  • Retrieve latest revision of a file from perforce using web url

    Hello,
    I am trying to retrieve the latest revision of a file from perforce using the web url and powershell. e.g.
    $Pforce = "perforce.test.com/@md=d&cd=//music/Database/DBA%20Scripts/&cdf=//msc/Database/DBA%20Scripts/20scrub%20script.sql&c=don@//music/Database/DBA%20Scripts/common%20script.sql"
    $CommonScrub = Invoke-WebRequest $Pforce  
    I am getting an error message below about invalid header. Does anyone have any ideas what this means and how to fix it?
    Is there another method I can use to get the files from perforce using powershell. Has anyone done this?
    Invoke-WebRequest : The server committed a protocol violation. Section=ResponseHeader Detail=Header name is invalid
    At E:\scripts\GetHTML_Headers.ps1:3 char:16

    Hi,
    You can set the headers via the -Headers parameter (this only works in V4):
    http://technet.microsoft.com/en-us/library/hh849901.aspx
    Also,
    from this article:
    Error: The server committed a protocol violation
    The Exception will tell what the HTTP protocol violation is: 
    "The server committed a protocol violation. Section=ResponseHeader Detail=Header
    name is invalid"
    Fix the server to conform to the HTTP RFCs to avoid this error.  .NET is a stickler that the HTTP Protocol be followed.
    Don't retire TechNet! -
    (Don't give up yet - 12,950+ strong and growing)

  • HT3775 why can't i play .wmv file in quicktime even after i download codec from windows? can anyone help me wit this please!!!!!

    why can't i play .wmv file in quicktime even after i download codec from windows? can anyone help me wit this please!!!!!

    Have you done the obvious things to try to fix it: quit Quicktime then start it back up again, log out then back in, reboot.
    Edit: Just read one of your later posts. If VLC won't play it, this is unrelated to Quicktime and Flip4Mac. Are you sure these wmv files are okay?

  • Help required with downloading files from inside WEB-INF folder

    I am working on a web application and I have an upload script which uploads different files to a foler called 'uploads' . To stop users from accessing the folder content I have put it in the /WEB-INF/.
    In my JSP file, I used to link to the uploaded files like this before for users to download them :
    if(filesListIterator.hasNext()
    files = (FilesBean)filesListIterator.next();
    <tr><td><a target="_new" href="<%=files.getFileName()%>">"<%=files.getFileName()%></a></td></tr>
    }I need to know how to alter the above link to make it access/download files from the /WEB-INF/uploads/ while still restricting direct access to the files.
    Thanks
    Message was edited by:
    topiwal

    Anything under WEB-INF is not directly accessible via the browser/ client. You could try defining the JSP/ Servlet inside web.xml deployment descriptor and see if you can access the file from there.
    I think a better way to accomplish this would be to keep the file outside WEB-INF , and use other techniques to protect the folder that contains the file - for example password-protection, or defining a .htaccess file and serving a 403 Forbidden error.

Maybe you are looking for

  • How to get the selected values from the shuttle

    Hi Please tell me how to get the selected option values from the shuttle leading list. Thanks

  • Error deploying new portal logon page

    Hi Gurus, I'm getting an error deploying my new portal logon page. I've made teh necessary changes to the portal.logon.par.bak file. I've rename it and made the necessary changes in config tool. i've created a new autoscheme_test.xml file and have as

  • Slow mac mini

    Mac Mini G4, 1.33 GHz 512 MB OS 10.4.11 Has suddenly begun slowing down when I have been loading web pages. This occurred a day or two after I installed Apple's Sept. 15 Security Upgrade. Also, I found a drop-down message in my network preferences th

  • Linking UDF to GL Account

    Hi all I have a UDF for which i want the amount to be accounted in one of the GL Accounts. How do i link the  UDF to a GL Account? Regards, Rohan S. Kamble.

  • Error encountered while communicating with primary IP-address

    Hi I have recently deployed my first Exchange Server. This is an Exchange Server 2013 Standard and I set up everything using this document on Technet for installation: http://technet.microsoft.com/en-us/library/bb124778(v=exchg.150).aspx For post-ins