Download an image to local machine

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • resmi318
    New Member
    • Jun 2007
    • 29

    Download an image to local machine

    Hi,

    I want to download a chart which I created using cfchart to excel and save it to local machine. The problem I am experiencing is when I save it in local machine,image is getting expired. The code I used to download to excel is

    [CODE=cfm]<cfif IsDefined("Exce llink")>
    <cfheader name="Content-Disposition" value="filename =chart.xls">
    <cfcontent type="applicati on/msexcel">

    <cfchart

    format = "jpg"
    chartHeight = "300"
    chartWidth = "500"
    style = "mystyle.xm l"
    showXGridlines = "no"
    showYGridlines = "yes"
    seriesPlacement = "default"
    foregroundColor = "black"
    dataBackgroundC olor = "white"
    showBorder = "yes"
    font = "arial"
    fontSize = "10"
    fontBold = "no"
    fontItalic = "no"
    labelFormat = "number"
    xAxisTitle = "WEEK"
    yAxisTitle = "ORDERS"
    sortXAxis = "no"
    show3D = "no"
    rotated = "no"
    showLegend = "yes"
    tipStyle = "MouseOver"
    showMarkers = "yes"
    markerSize = "4" >


    <cfchartserie s
    type="line"
    query="query1"
    itemColumn="WEE K"
    valueColumn="IT EMS"
    seriesColor="7f ff00"
    markerStyle="tr iangle"
    seriesLabel="IT EMS">
    </cfchartseries>
    </cfchart>
    </cfif>

    [/CODE]Can anybody help me?
    Thanks
    Resmi
    Last edited by acoder; Jan 22 '08, 09:40 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Does it expire immediately or after some time?

    Comment

    • resmi318
      New Member
      • Jun 2007
      • 29

      #3
      Originally posted by acoder
      Does it expire immediately or after some time?
      It expires immediately. Once I save it to local machine and open it. It displays image expired.

      Thanks
      Resmi

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        That's because the chart is stored in the cache and once the cache expires the image is no longer available. The image is not being stored in the Excel file - it's just a link. You can try copying the chart to another location outside the cache and link to that instead.

        Comment

        • resmi318
          New Member
          • Jun 2007
          • 29

          #5
          Originally posted by acoder
          That's because the chart is stored in the cache and once the cache expires the image is no longer available. The image is not being stored in the Excel file - it's just a link. You can try copying the chart to another location outside the cache and link to that instead.

          Hi,

          I tried to save the image by using the following code

          <cffile
          action="WRITE"
          file="mychart.j pg"
          output="#myChar t#">

          I set name attribute of cfchart to myChart.
          Then I tried to view image by <img src="new.jpg"> but it is not displayed.
          I checked whether image is present in the location and it was present.
          I also set debugging off by <cfsetting showdebugoutput ="no"> . Still its not working.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Try specifying the full path to the file:
            [code=cfm]<cffile
            action="WRITE"
            file="c:\images \mychart.jpg"
            output="#myChar t#">[/code]Also note that you're checking for new.jpg instead of mychart.jpg.

            Comment

            • resmi318
              New Member
              • Jun 2007
              • 29

              #7
              Originally posted by acoder
              Try specifying the full path to the file:
              [code=cfm]<cffile
              action="WRITE"
              file="c:\images \mychart.jpg"
              output="#myChar t#">[/code]Also note that you're checking for new.jpg instead of mychart.jpg.
              Hi,

              I tried giving the whole path. Still when it retrieve the image is empty.
              But image is present in the location.

              new.jpg was a mistake and is corrected.
              Thanks
              Resmi

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Now use that image in the Excel file.

                Comment

                • resmi318
                  New Member
                  • Jun 2007
                  • 29

                  #9
                  Originally posted by acoder
                  Now use that image in the Excel file.
                  Hi,

                  I am not able to retrieve that image.
                  Empty image is displayed

                  Resmi

                  Comment

                  • resmi318
                    New Member
                    • Jun 2007
                    • 29

                    #10
                    Originally posted by resmi318
                    Hi,

                    I am not able to retrieve that image.
                    Empty image is displayed

                    Resmi
                    Hi,

                    I found it is problem with path. Image is getting stored in default path and when I try to retrieve it is searching in current directory. I am not able to specify the default path. It is appending it to the URL

                    Resmi

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      Use an absolute path. If you want the default directory, it will usually be the temp directory which you can get with getTempDirector y().

                      Comment

                      • resmi318
                        New Member
                        • Jun 2007
                        • 29

                        #12
                        Originally posted by acoder
                        Use an absolute path. If you want the default directory, it will usually be the temp directory which you can get with getTempDirector y().
                        Thankyou acoder. With getTempDirector y() I am able to get temp directory and download as an image file. Only problem is I am not able to download as excel. When I download as excel it is giving binary format not image.

                        Resmi

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          If you try any normal image (not one generated using cfchart), is it still in binary format?

                          Comment

                          Working...