Force download of JPEG

Hi,
My servlet creates a JFreeChart with the writeChartAsJPEG function. The chart itself is created properly.
I would like to allow the user to open or save the file via a dialog box, but IE recognises the file type and displays the chart in the browser.
I have been searching the Internet for ages now and haven't found a solution to my problem.
Do you have a solution to open the dialog box instead of displaying the chart in the browser?
My code is the following:
public void doPost(HttpServletRequest request, HttpServletResponse response) {
try {
response.reset();
ChartUtilities.writeChartAsJPEG(response.getOutputStream(), getChart(request), 500, 300);
response.setContentType("application/force-download");
response.setHeader("content-disposition","inline; filename=Injury_Data.jpg");
} catch (Exception e) {e.printStackTrace();}
I have tried, without any success, the following actions:
- Replace "inline" per "attachment"
- Replace ".jpg" per ".zzz" or deleting extension
- Add response.setHeader("pragma","public")
- All sorts of MIME type: "image/jpeg", "application/unknown", "application/stream", "application/octet-stream", etc...
The problem is urgent now and i don't have any more leads to try and find a solution. Do you have any idea?
Thanks,
Christelle

I am doing something similar and mine works... Try setting the response headers before outputting the image. The only other differences I see are capitilization (Content-Disposition), and using quotes (") around the filename.

Similar Messages

  • Exe file not working with forced download script.

    I have a captivate file that I exported as an exe file for
    pc. It works fine when I download it from the server using the
    direct URL to the file but I don;t want people to actually see
    where it is located so I have a used a force-download php script.
    When I download it by way of the script... it downloads, but the
    file won't play. All I get is a DOS window pop up and then goes
    away. Same file...any ideas?
    The php file I'm using to force the download is below...
    <?php
    $filename = $_GET['file'];
    // required for IE, otherwise Content-disposition is ignored
    if(ini_get('zlib.output_compression'))
    ini_set('zlib.output_compression', 'Off');
    // addition by Jorg Weske
    $file_extension =
    strtolower(substr(strrchr($filename,"."),1));
    if( $filename == "" )
    echo "<html><title>Download
    Error</title><body>ERROR: download file NOT SPECIFIED.
    USE force-download.php?file=filepath</body></html>";
    exit;
    } elseif ( ! file_exists( $filename ) )
    echo "<html><title>Download
    Error</title><body>ERROR: File not found. USE
    force-download.php?file=filepath</body></html>";
    exit;
    switch( $file_extension )
    case "pdf": $ctype="application/pdf"; break;
    case "exe": $ctype="application/octet-stream"; break;
    case "zip": $ctype="application/x-compressed"; break;
    case "swf": $ctype="application/x-shockwave-flash"; break;
    case "doc": $ctype="application/msword"; break;
    case "xls": $ctype="application/vnd.ms-excel"; break;
    case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
    case "gif": $ctype="image/gif"; break;
    case "png": $ctype="image/png"; break;
    case "jpeg":
    case "jpg": $ctype="image/jpg"; break;
    default: $ctype="application/force-download";
    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0,
    pre-check=0");
    header("Cache-Control: private",false); // required for
    certain browsers
    header("Content-Type: $ctype");
    // change, added quotes to allow spaces in filenames, by
    Rajkumar Singh
    header("Content-Disposition: attachment;
    filename=\"".basename($filename)."\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($filename));
    readfile("$filename");
    exit();
    ?>

    Actually...never mind. This script creates a HUGE security
    risk....

  • I wish to upload a PDF file to my website but Firefox 3.6.12 reports it as type application/force-download and NOT application/pdf, WHY?

    My website has been running for many months, and as part of the site users can upload PDF documents to share with others. The last successful upload was 5th Nov, but to-day my upload was rejected because Firefox returned the document type as application/force-download rather than application/pdf. Uploads work fine with IE8.
    The site uses PHP to check extension and document type and, as I mentioned, has worked fine for many months. I have even attempted to upload the same document that succeeded on the 5th, but again Firefox returns application/force-download as the document type.
    Why the change?

    Just found a solution.
    In Tools, Options, Application Firefox listed TWO options against Adobe Acrobat Documents; the apprliaction/pdf and application/force-download. I have deleted mimeTypes.rdf and allowed Firefox to re-create the file. All works as it should now!

  • Force download

    Hi!
    I want to know how to "force" the downloads. I mean that if the user can open the file, the file doesn't opens and give the choice to the user to download it.
    For example, if the user have installed "adobe reader" in his computer and wants to download a pdf file, the file doesn't open in the browser and give the option to download.
    How I can do it?
    PD: I have Dreamweaver CS4.

    You can Zip the file and in most cases this will work.
    Yourfile.pdf becomes YourFile.zip.
    Or, do a Google search for Force Download script in the programming language your server supports.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb
    http://alt-web.blogspot.com

  • Has anyone maxed out their storage since iOS 7 update forces download of all email?

    Has anyone maxed out their storage since iOS 7 update forces download of all email? I'm on my way to that end. I will have to delete my email accounts. Apple told me to do so and just use the providers' apps instead of iPhone accounts. This pretty much renders my smartphone useless. Not to mention I no longer like using my phone since this awful update. Not as intuitive or fun!

    (A) Reset iPad
    Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
    (B) Make sure sound is not muted in Control Center; tap on the little bell. Swipe upwards from bottom of screen to launch Control Center

  • Force downloading mysite HD photos from Exchange 2013

    Hi Sharepoint Admins,
    I want to force download all HD photos from Exchange 2013 into users mysite profiles. I already provisioned all user mysites by powershell. HD photos are also available, but every user has to open his own mysite by himself to trigger the picture download.
    The goal is to download photos without having every user to logon on their site.
    Is there any way to force this?
    "SharePoint Server 2013 requests photos from Exchange 2013 automatically when a user performs an operation that causes a request for their own photo (for example, browsing to their own user profile page). That means that the user needs to have requested
    his/her own photo, before other users will be able to see it."
    Best Regards
    Markus Kühn

    Hi Markus,
    I understand you would like to manually sync HD photo from Exchange 2013 to SharePoint 2013 mysite.
    Since "SharePoint Server 2013 requests photos from Exchange 2013 automatically when a user performs an operation that causes a request for their own photo (for example, browsing to their own user profile page)", you need to browse all
    sites in Mysite web application.
    To do this, you may refer SharePoint warmup script and make the script to work for you MySite web application. Just run the warmup script, all mysites can be browsed once.
    https://gallery.technet.microsoft.com/office/SharePoint-2007-2010-or-d1884b4b
    https://spbestwarmup.codeplex.com/
    Regards,
    Rebecca Tu
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Firefox downloads pictures as plain text files, i need to download a jpeg file in windows xp

    if i download the jpeg image from google images in firefox, save as type in text document only appear. not jpeg or other format not appear. i want to save as type in jpeg format only. pls help us.

    Right click on the image and choose "save image as"
    If your in image.Google.com then it save as .html file only
    open the image file in new tab and save it.

  • Force Download PDF code - getting "could not open" error

    Hello I am having some trouble with some "force download" code. I have spent many days on google looking for a good tutorial / script but there appears to be issues with everyone of them that I try.
    I came across a simple one that I got sort-of working, however the PDFs that it downloads error for some reason. The PDF when trying to open (in adobe reader) produces the following error:
    Could not open '3GLG534WW.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
    My website with an example download link is: http://www.reese-test2.co.uk/3GLG534WWc.php - click on the green button on the download tab
    Does anyone know what I need to alter to get it to work? code below on my script (downloadSPECS.php) and underneath that the code on the actual link to the PDF
    The script code (downloadSPECS.php) :
    <?php
    $pdf = substr($_SERVER['PATH_INFO'], 1);
    if(preg_match('/^[a-zA-Z0-9_\-]+.pdf$/', $pdf) == 0) {
      print "Illegal name: $pdf";
      return;
    header('Content-type: application/pdf');
    header('Content-disposition: attachment; filename=' . $pdf);
    readfile('http://www.reese-test2.co.uk/Downloads/Specs' . $pdf);
    ?>
    The code on the green button / PDF link:
                  <p><a href="http://www.reese-test2.co.uk/scripts/downloadSPECS.php/3GLG534WW.pdf" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('SpecDL','','images/specDLB.jpg',1)"><img src="images/specDL.jpg" alt="Download Spec Sheet" width="196" height="71" id="SpecDL" /></a></p>
                  <p> </p>

    Hi thanks all for your answers.
    The PDF is def ok. you can see it fine when you put the PDFs address in the browser:
    http://www.reese-test2.co.uk/Downloads/Specs/3GLG534WW.pdf
    I changed the 1 to a 0 but got a "illegal name" error
    I have tried a few other things like adding the extra parts to the script (see code below - ob_clean and flush): Still not working though!
    I have tried changing the readfile location - adding public_html and tried a few other things, but cant make it work! Could there be a file size problem maybe? is there a code to allow for this?
    thanks
    Sara
    <?php
    $pdf = substr($_SERVER['PATH_INFO'], 1);
    if(preg_match('/^[a-zA-Z0-9_\-]+.pdf$/', $pdf) == 0) {
      print "Illegal name: $pdf";
      return;
    header("Cache-Control:  maxage=1");
    header("Pragma: public");
    header('Content-type: application/pdf');
    header('Content-disposition: attachment; filename=' . $pdf);
    readfile('http://www.reese-test2.co.uk/public_html/Downloads/Specs' . $pdf);
    ob_clean();
    flush();
    readfile($file);
    ?>

  • Force download video in stead of using the cache ?

    Hello,
    Does anyone has expierence with the fact that when you
    connect to an flv file to play video in flash
    the first time it will download the flv file. But suppose i
    change the content of the flv file but keep the name the same it
    will play the previous video because it's using the cache of
    IExplorer.
    Is there a way to force the download? Or a way when the movie
    is finished to clear that cached movie?
    I also tried to unload the movie, but that doesn't do the
    trick.
    If someone has a fix for this, please let me know.

    Hello Michael,
    > I am still very new action scripting, so please bear
    with me when I
    > ask newbie questions.
    >
    > Dave, would that also apply to loading other files, such
    as text?
    > My current action reads thus:
    > loadVariablesNum("news.txt", 0);
    > stop();
    > As with the OP, this is loaded into the cache and isn't
    always
    > updated when the visitor returns to the site.
    >
    > Would this be an appropriate revision to the code?
    >
    > loadVariablesNum("news.txt?r=", 0) + getTimer();
    > stop();
    loadVariablesNum("news.txt?r="+ getTimer(), 0) ;
    stop();
    btw. it's absolutely unnecessary to add hash as a parameter.
    you can just
    ad it right after "?" symbol.
    Hash purpose is to make your URL unique to browser. Also, if
    you *** this
    hash as a parameter in a URL-encoded string - you pass this
    parameter to
    flash (if dealing with links to flash files) and it's OK if
    you use it further,
    but do you need additional garbage if not? )

  • ITunes Match forces download from iCloud when iPhone is attached to my Mac?

    I got iTunes Match just before christmas and I, like a lot of people have been having trouble with the artwork. So I decided to reset my iPhone to wipe all the music off...everything is backed up and I've done this before and it's fixed problems.
    My phone is physically attached to my Mac and I go to sync my playlists and I face a screen saying "iPhone can access music in iCloud. Songs can be downloaded and played via wifi" Why am I forced to download off iCloud when it HAS to be easier to sync off my Mac?
    The phone point of getting iTunes Match was to add to my music listening experience not to take away from it. Now I have to manually add songs and playlists when before it was just selecting a few tick-boxes and saying sync. Why am I paying for this service?

    83years wrote:
    Why am I paying for this service?
    I assume because you signed up for it.
    I'd leave feedback with Apple, as this is a user to user forum so they will not necessary see your comments.
    There is a way round adding lots of music onto your phone by USB. I haven't done it personally, so you may want to do a search on here, but I believe that basically you turn off Match on your phone, sync as previously and then turn it back on.
    As I say, I haven't tried it myself, so best do a quick check first.

  • HT4101 downloading only JPEG files using SD card reader

    I am new to Apple-iPad world,, mostly working on WinXP.
    I am looking to buy a tablet to view photos while I'm on vacation and traveling. I shoot both RAW and JPEG files of each image. When I connect my SD card to an iPad Mini, I'd like to be able to download only the JPEG files, since the RAW files are too large and would quickly fill up my device.
    I've been told that when you plug in the Apple SD card reader, it treats the RAW and JPEG files of an image as one, so when you download you have no choice to just select the JPEGs. Seems like a huge oversight on Apple's part, to offer camera and card connection, but then be so controlling about it, that it doesn't work for people. None of the 3-4 Apple sales reps I've spoken to know of a way around this.
    At this point, I'm lookng at an Android tablet instead, since it doesn't have this limiting feature--though I much prefer the look and size of the iPad Mini screen.  .
    Has anyone else run into this issue? Any thoughts on a work-around?
    (Two solutions that I've thought of--though I don't know if they will work--are: 1) download all of the images, then bring them up in a program like Snapseed, where I can save (really a 'save as') a new JPEG version of my image, then delete the original files that I downloaded, or 2) see if I can download a file manager app that would let me view the different files by size and by type (to identify the RAW files), then delete just these from me iPad)  
    Best, David.

    Thanks Tom, at last an answer!
    So it seems I would need to first download the image files to my tablet--including RAW files--(or whatever the constraits are in working with the Apple SD card reader), and then after the fact, use PMP to delete just the RAW files.
    I assume then that PMP can view the 'standard' photo folders (called 'Albums on my iPod) created by the Apple photo app (or by the iOS, I'm not sure), is that correct?
    This might be an acceptable work-around for me.
    Best, David.  

  • Force downloads/kill streaming in Podcasts app?

    I need to know that my podcasts are downloaded and available when I am not connected to the internet.
    With iOS7 and the new podcasts app, is there any way to FORCE them to download and not ever try to stream?  I listen to sometimes dozens of podcasts a day as a continuous play list, and tapping each one to download is really not a reasonable approach--like when you're in the car driving several hundred miles at a time, it's not safe to be clicking next, next, next to get to a podcast in the list that might have actually been downloaded to the device. 
    It was easy with iOS 6--download podcasts to computer when conveniently situated for wifi, sync to iOS device at leisure, listen offline....

    Also would appreciate suggestions for a 3rd party podcast app that can be set to only download can sync what's been played to podcasts on the computer--I need the capacity to listen from either device. 

  • Force download of file on mac?

    I have some inDesign files that are posted on a site. I have
    created links
    to them but with the mac, it wants to just open them in the
    browser; it
    doesn't just download them .
    How do I force a download?
    Lee Arthur Fairbanks
    American Educational Products LLC
    Web Designer/Developer
    Voice - 715.723.4427 x132
    Fax - 715.723.8021
    Hubbard Scientific
    1120 Halbleib Road
    P.O. Box 760
    Chippewa Falls, Wisconsin 54729
    www.shnta.com
    [email protected]

    David:
    There is no way to create a domain file from the published files. You will have to recreate the site from scratch. You can use, however, the image files that were uploaded for the site so you don't need to go rummaging around trying to find the originals.
    The older version would probably be a better option than starting from scratch. You can compare what you see in Safari against iWeb and then use the files that were created for the site to add to what you have in iWeb.
    In the future I suggest you make another copy of the newest version of the domain file as you exit iWeb on each location. You can modify varkgirl's Automator application to backup the Domain.sites file to back it up from the Flash drive to a folder on each location before ejecting the flash drive. You can get it here: http://www.varkgirl.com/Varkgirl/iWeb%20Tips.html
    Do you Twango?

  • Why is Adobe forcing downloads of Chrome and Google Toolbar?

    Before someone states there is an option, I was given absolutely no option to decide to accept Google Chrome or Google Toolbar. I am forced to use Adobe reader from a Pearson
    because of classes. I go to the download link, click run. And there you go, Adobe downloads Adobe Reader, Google Tool Bar, and Google Chrome.
    I do NOT want this crap on my computer.
    Now I have to go uninstall this. If I wanted Google Chrome or ANY toolbar I would download it myself. Forcing anyone to download software with no option is a stupif PR move.
    Its only going to make people angry.

    If you download Adobe Reader from http://get.adobe.com/reader/ there is a checkbox to remove optional software from the download.
    If you download Adobe Reader from http://get.adobe.com/reader/enterprise/ there is no bundled software with it.
    Lots of companies offer bundled software with free products; it is usually your choice to refuse the offered 3rd party software.

  • How to download a jpeg file from a webpage, daily, automatically

    Hello,
    do you know any app or Automator script that allows me to download an image from a webpage, everyday at the same hour, and without doing any action?
    I need that the Mac will do it automatically.
    Thanks.

    Well, first it would depend on DRM protection (copyrights of the author) whether you can legally download it at all.
    Aside from that, you would also have to automate your Mac to be on that very specific website, connected to the internet, with the mouse choosing which specific image you want to download (as websites can contain many images).

Maybe you are looking for