9 Replies Latest reply on Aug 21, 2008 10:03 AM by Gakusei

    refreshing an image after upload

    Gakusei
      OK, I've been banging my head against this one for a couple of days now...

      I've got an app that displays a user photo. Next to it, is a button that allows the user to upload a new picture. I'm sending the uploaded file to a ColdFusion page that does the upload and overwrites the existing file (so it has the same name). And it does do the upload, but it won't update the picture on the page. I can move from user to user, but when I return to the user in question it's still the old pic... it doesn't refresh to the new one until I refresh the entire app in the browser... which is a deal killer.

      How can I code this to work the way I need it to?

      HELP!

      Thanks in advance,

      bw
        • 1. Re: refreshing an image after upload
          Level 7

          "Gakusei" <webforumsuser@macromedia.com> wrote in message
          news:g848ro$ho0$1@forums.macromedia.com...
          > OK, I've been banging my head against this one for a couple of days now...
          >
          > I've got an app that displays a user photo. Next to it, is a button that
          > allows the user to upload a new picture. I'm sending the uploaded file to
          > a
          > ColdFusion page that does the upload and overwrites the existing file (so
          > it
          > has the same name). And it does do the upload, but it won't update the
          > picture
          > on the page. I can move from user to user, but when I return to the user
          > in
          > question it's still the old pic... it doesn't refresh to the new one until
          > I
          > refresh the entire app in the browser... which is a deal killer.
          >
          > How can I code this to work the way I need it to?

          What are you doing now?


          • 2. Re: refreshing an image after upload
            Gakusei Level 1
            Thanks in advance....

            Here are some code snippets that I've been using...
            • 3. Re: refreshing an image after upload
              Level 7

              "Gakusei" <webforumsuser@macromedia.com> wrote in message
              news:g84cfo$lm7$1@forums.macromedia.com...
              > Thanks in advance....
              >
              > Here are some code snippets that I've been using...
              >
              > in the main app, I have the following items:
              > <mx:Image id="RecPic" x="519" y="378" width="175" height="175"
              > autoLoad="false" cacheAsBitmap="false" cachePolicy="off" />
              > <mx:Button label="Upload Photo" icon="@Embed('/icon/add.png')"
              > id="btn_RecPicUpl"
              >
              > click="showAddDoc2(currentRecruiterMetadata.getItemAt(0).INTINDID,'RecPic');"
              > disabledIcon="@Embed('/icon/disabled/add.png')" x="702" y="378"/>
              >
              > then from the component pop up, it has the following event handler:
              > private function completeEvent(event:Event):void {
              > currentState = 'uploaded';
              > mx.core.Application.application.wsVAE.selectRecruiters_Event2.send();
              > mx.core.Application.application.reloadPic();
              > }
              >
              > which calls a webservice with the following handler
              > public function
              > handleselectRecruitersEvntResult2(event:ResultEvent):void{
              > selectContacts_RecruiterEvnt=event.result as Object;
              > doRecStuff();
              > }
              >
              > which calls
              >
              > public function doRecStuff():void {
              > ...
              > if (currentRecruiterMetadata.getItemAt(0).BITPHOTO == "1") {
              > RecPic.source = "vae_docs/VAE_RecPic_" +
              > currentRecruiterMetadata.getItemAt(0).INTINDID + ".jpg";
              > } else {
              > RecPic.source = "vae_docs/VAE_RecPic_0.jpg";
              > }
              > RecPic.load();
              > ...
              > }
              >
              >
              >
              > the popup component's result handler call this function in the main app as
              > well
              > public function reloadPic():void {
              > RecPic.source = "vae_docs/VAE_RecPic_" +
              > currentRecruiterMetadata.getItemAt(0).INTINDID + ".jpg";
              > RecPic.load();
              > doRecStuff();
              > }
              >

              I don't see anything that changes this:

              currentRecruiterMetadata.getItemAt(0).INTINDID , which looks like it is the
              identifying part of your image.

              HTH;

              Amy


              • 4. Re: refreshing an image after upload
                Gakusei Level 1
                true... but the user isn't changing... i just want the newly uploaded file to show up in the image container...
                • 5. Re: refreshing an image after upload
                  Level 7

                  "Gakusei" <webforumsuser@macromedia.com> wrote in message
                  news:g84m1c$2c0$1@forums.macromedia.com...
                  > true... but the user isn't changing... i just want the newly uploaded file
                  > to show up in the image container...

                  Try adding a timestamp to the end of the url to tell the computer it's a
                  unique request:

                  "vae_docs/VAE_RecPic_" +
                  currentRecruiterMetadata.getItemAt(0).INTINDID + ".jpg?"+(new
                  Date()).milliseconds;

                  HTH;

                  Amy


                  • 6. Re: refreshing an image after upload
                    Gakusei Level 1
                    OK... this works... but only in Firefox... it still caches in IE... we're soooooo close...

                    any other ideas?

                    thanks again in advance,

                    bw
                    • 7. Re: refreshing an image after upload
                      Level 7

                      "Gakusei" <webforumsuser@macromedia.com> wrote in message
                      news:g85h10$t1r$1@forums.macromedia.com...
                      > OK... this works... but only in Firefox... it still caches in IE... we're
                      > soooooo close...
                      >
                      > any other ideas?
                      >
                      > thanks again in advance,

                      Try looking at the cachePolicy and cacheAsBitmap properties.

                      HTH;

                      Amy


                      • 8. Re: refreshing an image after upload
                        Gakusei Level 1
                        i've got cacheAsBitmap set to false, and cachePolicy set to off... same result.... sigh
                        • 9. Re: refreshing an image after upload
                          Gakusei Level 1
                          Solved the issue by creating a canvas that contains the image... then using RemoveAllChildren and AddChild to remove the old image and add the new image...