Setting the name of streamed zip file

Hi,
I have a servlet which creates a zip file with documents retrieved from a database. To create the zip file I am using the ZipOutputStream class and adding the documents one at a time to this object. This is all working fine.
The problem I have is pretty simple, in that I can't seem to find a way in which to set the name of the zip file. This must be possible! At the moment it appears to be setting the name of the zip file to the name of the class that created it. In this case my class is called DocumentPacker and what comes back from the servlet is a zip file called DocumentPacker.zip. This wouldn't be so bad, but if you're creating the zip file for a user that does not have cookies enabled, it appends the session id to the end of the zip file name which i don't want.
I am creating my ZipOutputStream like this:
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
and then adding the documents one at a time using a BufferedInputStream.).
Any help on how to set the name would be much appreciated
Thanks
Claire

Your servlet must set some headers on the HTTP response (Content-Type as "application/zip", Content-Disposition as "attachment; filename=yourfilename.zip")
Read the RFC1806 document.
Content-Type: application/zip
Content-Disposition: attachment; filename=genome.jpeg

Similar Messages

  • How to set the name for an 'unknown' file extension?

    Specifics:
    I have various file extensions that are recognized by my mac. I would like to know how to create a list of applications that can open it so I do not get a 'There is no Default Application to open this file' error. I would also like to be able to give these file extensions names recognized by the mac.
    Just like .txt is a "Textedit Document" and .html is a "HTML Document," I'd like to be able to change the name and assosication of a file and give it its own .icns if possible.
    As for the default applications, I know how to set a default application. However, if a mac does not recognize a file extension, adding a new default application to run the file wil actually erase the old one, which is a big pain, especially when your file can be opened with ANY text editor.
    I understand that this may involve hacking into the operating system's databases, but if anyone can help, it would be greatly appreciated.

    Hi Timo,
    My jdev version is 10.1.3.3.0, this is for R12. By PR i mean to say process request and PFR process form request in the controller.
    In the Process request of the controller, i am finding the checkbox bean and assigning the firepartialaction for it.
    Later in the process form request for the fired event, i am trying to handle the rendered property of the messagetextinput. Is this a right approach?
    my code below
    public void processRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    super.processRequest(oapagecontext, oawebbean);
    OAApplicationModule oaapplicationmodule = oapagecontext.getApplicationModule(oawebbean);
    OAMessageCheckBoxBean oamessagecheckboxbean = (OAMessageCheckBoxBean)oawebbean.findChildRecursive("X_FLAG");
    if(oamessagecheckboxbean != null)
    oapagecontext.writeDiagnostics(this, "Message check box Bean found:", 1);
    FirePartialAction firepartialaction = new FirePartialAction("change");
    oamessagecheckboxbean.setAttributeValue(PRIMARY_CLIENT_ACTION_ATTR, firepartialaction);
    oamessagecheckboxbean.setFireActionForSubmit("change", null, null, true);
    oapagecontext.writeDiagnostics(this, "setting fire event", 1);
    public void processFormRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    super.processFormRequest(oapagecontext, oawebbean);
    oapagecontext.writeDiagnostics(this, "Inside Process Form Request", 1);
    if("change".equals(oapagecontext.getParameter(OAWebBeanConstants.EVENT_PARAM)))
    OAMessageTextInputBean bean = (OAMessageTextInputBean)oawebbean.findChildRecursive("X_NUMBER");
    if(bean!=null){
    bean.setRendered(Boolean.TRUE);}
    Thanks,
    Malar

  • Setting the name of a file to be uploaded

    I'm having trouble setting the name that my uploaded files get when they are saved on my server. I upload the files useing the following:
    <html>
    <head>
    <title>File Upload</title>
    </head>
    <body>
    <%@ page import="java.io.*" %>
    <% if (request.getContentLength() <= 1)
    { %>
         <form method=post enctype="multipart/form-data">
         <input type=file name="file">
    <input type=submit value="Submit" name="Submit">
    <input type="text" name="fileName">
    </form>
    <%
    if (request.getParameter("Submit") != null)
    out.println(request.getParameter("file"));
    else
    String contentType = request.getContentType();
    String tempFieldType = request.getParameter("fileValue");
    if ((contentType != null)&&(contentType.indexOf("multipart/form-data") != -1))
    try
    ServletInputStream sis = request.getInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int length = request.getContentLength();
    int read = 0;
    if (length != -1)
    for(int i = 0; i < length; i++)
    read = sis.read();
    baos.write(read);
    sis.close();
    String data = baos.toString();
    String origData = data;
    int boundaryStart = contentType.indexOf("boundary=");
    String boundary = contentType.substring(boundaryStart,contentType.length());
    boundary = boundary.substring((boundary.indexOf("=")+1),boundary.length());
    int gifStart = data.indexOf("\r\n\r\n")+4;
    int gifEnd = data.indexOf("--"+boundary,gifStart);
    File file;
    String filename = request.getParameter("fileName");
    out.print(filename);
    while(true)
    if (data.indexOf("image/gif") != -1) filename = filename+".gif";
    if (data.indexOf("jp") != -1) filename = filename+".jpeg";
    file = new File("C:\\"+filename);
    if(!file.exists())
    break;
    PrintStream pr = new PrintStream(new FileOutputStream(file));
    pr.write(baos.toByteArray(), gifStart, gifEnd-gifStart);
    pr.close();
    baos.close();
    catch(Exception exp)
    { out.println(exp); }
    %>
    </body>
    </html>
    I think my problem is in the <form method=post enctype="multipart/form-data"> this method is not letting me get the updated values of the text box fileName.
    Does somebody know how do get these values?
    thanks for you help,
    snnkmtt

    try to use jspsmartupload and see this post
    http://forum.java.sun.com/thread.jsp?forum=45&thread=81638&start=0&range=100
    thank you
    looking for ur solution
    all the best
    yours
    rajesh
    [email protected]

  • How to dynamically set the name of the generated PDF file sent by email

    Hello,
    I am using Reports 10g and I managed to send PDF reports by email, specifying the recipient, subject, format etc, using the reports servlet URL.
    But there is one thing that I cannot find a way to do: I want to dynamically set the name of the attached file. It defaults to the name of the RDF file (eg monthly_sales.pdf). I would like it to be something more meaningful (eg monthly_sales_072010.pdf, where 072010 is the month and year passed by parameters).
    Is it possible to do it?
    Thanks
    Luis

    Use System.load(...) instead of System.loadLibrary(...).

  • Java mapping - Setting the name of the file dinamically

    Hi all,
    Problem: I know how to set the name of the file in an Idoc to file interface if I'm using a message mapping, but not if I'm using a Java mapping.
    I'm using this code inside a user-defined function of the message mapping so that I can set the name of the file dinamically:
    public String GetFileName(String  inboundParameter,String IdocNumber,Container container){
    String filename;
    java.text.SimpleDateFormat dateformat = new java.text.SimpleDateFormat( "yyyyMMdd" );
    filename = "cikk_" + dateformat.format( new java.util.Date() ) "_" IdocNumber + ".txt";
    DynamicConfiguration conf = (DynamicConfiguration) container
           .getTransformationParameters()
           .get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "FileName");
    conf.put(key, filename);
    return inboundParameter;
    (See also: /people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14)
    But how can I do that if I'm using a Java mapping??
    I don't have the class Container there. How can I retrieve the DynamicConfiguration object without that class?
    Thank you very much.

    Thank you Jin,
    I knew that it had to be related with the Map object got in setParameter, but in this link:
    http://help.sap.com/saphelp_nw04/helpdata/en/0f/80243b4a66ae0ce10000000a11402f/frameset.htm
    you can't find the constant DYNAMIC_CONFIGURATION.
    I think it's not up to date.

  • To upload the ZIP file and get the filenames available in ZIP file in ABAP

    Hi Experts,
    For my requirement, file from legacy comes as ZIP file with number of files in that.
    Please provide one code sample to upload the ZIP file from local workstation and get the filenames available in ZIP file to check few filename validation checks for the available files in report program.
    Thanks in Advance,
    Regards,
    Basani

    1. Copy the ZIP file into App server
    2. Call function
      call function 'RFC_REMOTE_PIPE'
        destination 'SERVER_EXEC'
        exporting
          command = command  " Unzip command gunzip /path & file
          read = 'X'
        tables
          pipedata = std_lines
    then you can read the files and can validate the file names

  • Set the name of cell or cells' range for a report and when export it to excel the names will be defined.

    Hello,
    I have an C# application that exports report from Reporting Services to Excel files.
    I would like to know if there is a possibility to set the name of the cell or range of cells in the report (via Report Builder or somewhere else) and when open the Excel the names are set. Similar functinality when you open the Excel and go Formulas/Define
    Name and set the name for a unique cell or range.
    Regards,

    Hi there,
    I don't believe this is possible in Reporting Services.  One workaround, if you don't know the exact range at runtime, might be to put hidden characters (white?) in your sheet at start and end of range, then do some postprocessing on the file using
    VSTO or perhaps a 3rd-party tool like this one.  
    http://www.aspose.com/reporting-services/excel-component.aspx
    If you do know the range it should be much easier.
    cheers,
    Andrew
    Andrew Sears, T4G Limited, http://www.performancepointing.com

  • Error in reading the contents of a zip file

    EHello Experts,
    I want to read the contents of a zip file.I have written the following program which reads the contents of a file named "index.xml" which resides in ReadZip.zip.My problem is , it is reading only the first line of that file & after that it is giving this error.
    java.io.IOException: Stream closed
    at java.util.zip.ZipInputStream.ensureOpen(ZipInputStream.java:43)
    at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:67)
    at components.ReadZipFile2.main(ReadZipFile2.java:26)
    public class ReadZipFile2 {
        public static void main(String args[]) {
            try {
                FileInputStream fis = new FileInputStream("C:\\ReadZip.zip");
                ZipInputStream zis = new ZipInputStream(fis);
                ZipEntry ze;
                while ((ze = zis.getNextEntry()) != null) {
                    System.out.println(ze.getName());
                    if (ze.getName().equals("ReadZip/index.xml")) {
                        long size = ze.getSize();
                        if (size > 0) {
                            System.out.println("Length is " + size);
                            BufferedReader br = new BufferedReader(
                                    new InputStreamReader(zis));
                            String line;
                            while ((line = br.readLine()) != null) {
                                System.out.println(line);
                            br.close();
            } catch (IOException e) {
                e.printStackTrace();
    }It seems that zis is getting close after reading the first entry of file.I am unable to guess the reason for this.Please help.Thanx in advance.

    [redacted confused advice]
    [_Compressing and Decompressing Data using Java - with many code samples_|http://java.sun.com/developer/technicalArticles/Programming/compression/|Yes Virginia, there really are code samples]

  • I have really slow internet, i bought OS X mountain lion & tried for days to download it. my internet cuts every time & the download restarts from the beginning is thr a way to download the software as a "zip" file or from a link not app store?

    I have really slow internet, i bought OS X mountain lion & tried for days to download it. my internet cuts every time & the download restarts from the beginning is thr a way to download the software as a "zip" file or from a link not app store?

    MacBook Pro
    https://discussions.apple.com/community/notebooks/macbook_pro 
    https://discussions.apple.com/community/mac_os/mac_os_x_v10.7_lion?view=discussi ons
    http://www.apple.com/support/macbookpro
     Take it somewhere that has better broadband. The best you can do sometimes is invest in new modem that works with your system instead of the rental etc in most cases.
    Do a Safe Boot.
    Make sure your firewall is set properly. Don't use 3rd party. AV software can get in the way.
    Make sure you are getting the service and a clean strong modem signal - slow is one thing but if it drops off and can't maintain a connection you have hardware issues, not software - and upgrade to a new OS doesn't tend to improve, it may even not work with older networking equipment once you do get it.
     I agree and think electronic only goes too far. And when you do get it: burn the package and manually set it aside first before running the intaller! make a flash memory installer, put it on DVDs too.

  • Panagon and MGETDOC Application:open a doc, the doc goes to .zip file instead of going to the doc directly

    Application: FileNet content SG (Panagon) and MGETDOC(Web application)
    Issue: when open a doc, the doc goes to .zip file instead of going to the doc directly. Only this issue happens for .xlsx,docs and pptx document.
    Note: On all client machine, we are using office 2007 and IE8 browser
    Cause: On 16<sup>th</sup> July 2013, . Net framework 4.5 is install on all our GI-D desktop machines. There after the issue is started .
    Application Background: Applications built on .net framework 1.1 and it can support up to 4.0 version on client machine to view the documents through panagon and MGETDOC application. Panagon (Filenet content services) is
    not supported in .net framework 4.5 and above.
    Work around: After I had troubleshooting and tested with one of our  system which has .net framework 4.5, IE8 does not support with HTML5 and tested with IE9 and Chrome, documents were able to open successfully.
    I had removed .Net framework 4.5 uninstalled and able to open the documents w/o any issue. And also we had give the work around as if the doc goes to zip file, they open the doc by removing the . zip extension and they can save it as .xlsx or docx file and
    they can able to open file.
    Please let us know if you there is a fix to export the files through framework 4.5 and do contact us if you need further details, we shall discuss on the same. Thank you for your support. Request you to email @
    [email protected]/[email protected]
    Candida

    Presumably you're using Safari?
    You can change that in Safari Preferences (at least in 5.0.3, might be different in 5.1.x)
    The checkbox at the bottom will do that for you. However! I strongly advise against permitting that; there have been, and no doubt will be again, malware that uses that to bypass authentication.
    Just select Desktop as the default download location so you don't have to dig for the files.

  • Setting the name of a new object from a string

    Is there anyway I can set the object name of a newly created
    object from a string?
    eg.
    (the code below generates a compile time error on the
    variable declaration)
    public function addText(newTxt:String, txt:String,
    format:TextFormat):void {
    var
    this[newTxt]:TextField = new TextField();
    this[newTxt].autoSize = TextFieldAutoSize.LEFT;
    this[newTxt].background = true;
    this[newTxt].border = true;
    this[newTxt].defaultTextFormat = format;
    this[newTxt].text = txt;
    addChild(this[newTxt]);
    called using>
    addText("mytxt", "test text", format);
    I could then reference the object later on without using
    array notation using mytxt.border = false; for example
    There are many a time when I want to set the name of a new
    object from a string.
    In this example I have a function that adds a new text object
    to a sprite.
    The problem is, if I call the function more than once then
    two textfield objects will exist, both with the same name. (either
    that or the old one will be overwritten).
    I need a way of setting the name of the textfield object from
    a string.
    using
    var this[newTxt]:TextField = new TextField()
    does not work, If I take the "var" keyword away it thinks it
    a property of the class not an object.
    resulting in >
    ReferenceError: Error #1056: Cannot create property newTxt on
    Box.
    There must be a way somehow to declare a variable that has
    the name that it will take represented in a string.
    Any help would be most welcome
    Thanks

    Using:
    var this[newTxt]:TextField = new TextField()
    is the right approach.
    You can either incrment an instance variable so that the name
    is unique:
    newTxt = "MyName" + _globalCounter;
    var this[newTxt]:TextField = new TextField();
    globalCounter ++;
    Or store the references in an array:
    _globalArray.push(new TextField());
    Tracy

  • How do I change the name property of a file in a document library?

    I am trying to come up with an Event Receiver that will change the name property of an file when it is uploaded. For instance when a file is uploaded into a document Library, currently the Title is being generated (which is fine)...I want to be able to
    change the "Name" property from whatever it is, to match exactly what is in the "Title" property. Are there any sample codes/blogs out there that I can take a look at? Has anyone  had any experience doing this? It seems like something
    that should be straight forward, to change the "Name" property to match what is in the "Tilte" property.

    Hi,     
    You can try the code below which use the SPFile.MoveTo() function to change the name of the file.
    EventFiringEnabled = false;
    SPFile f = properties.ListItem.File;
    string spfileExt = new FileInfo(f.Name).Extension;
    f.MoveTo(properties.ListItem.ParentList.RootFolder.Url +
    "/" + properties.ListItem["Title"]+ "_new" + spfileExt);
    f.Update();
    EventFiringEnabled = true;
    Here is a similar thread for your reference:
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/5cafb8e4-bb85-4147-9bda-4ab42a4d4817/sharepoint-2013-event-receiver-to-rename-files-not-working?forum=sharepointdevelopment
    A link about rename uploaded file using Event Receiver for your reference:
    http://paulgalvinsoldblog.wordpress.com/2008/01/25/quick-easy-rename-uploaded-file-using-sharepoint-object-model-via-an-event-receiver/
    Best regards
    Patrick Liang
    TechNet Community Support

  • How do you change the name of a folder/file on an expansion drive

    How do you change the name of a folder/file on an expansion drive or external hard drive?

    The same way you change it on the internal drive; click on the name and wait a second or two for the field to drop into editing mode, then just type the new name. Or Get Info on the file/folder and change the name there.
    Regards.

  • How to extract the audio of a zip file? if it helps I'm trying to add this album zip to my library

    how to extract the audio of a zip file? if it helps I'm trying to add this album zip to my library

    Let's say you have a zipped audio collection (audio.zip) containing mp3 files. And you are at a Terminal prompt.
    List the files in the zip archive
    unzip -l audio.zip (that is ell)
    Extract all mp3 audio files into a new home directory folder called mymusic
    unzip -d ~/mymusic audio.zip \*.mp3
    Variations of the above will depend the zip contents, and internal structure. If the zipped audio collection was gzipped, or someone used rar on it, then the extraction process will be different.

  • When I try to convert my .pdf to Word, I get a sidebar that has fields for: the name of my pdf file, the type of file I want to convert to (In my case, Word), and a button that says "Convert".  My problem is that the "convert to" field isn't active.  I ca

    When I try to convert my .pdf to Word, I get a sidebar that has fields for: the name of my pdf file, the type of file I want to convert to (In my case, Word), and a button that says "Convert".  My problem is that the "convert to" field isn't active.  I can see the words "Microsoft Word" in pale gray, but when I click on the field, nothing happens.

    You have posted in the wrong forum.  Try posting in the forum for the product you are trying to use.
    Here is a link to a page that has links to all Adobe forums... use the drop down list to see all.
    Forum links page:
    https://forums.adobe.com/welcome

Maybe you are looking for