14 Replies Latest reply on Apr 24, 2006 1:25 AM by BKBK

    How can we handle posted binary data??

    Shigeru@Linkcom Level 1
      Hello.

      How can we handle posted binary data with CFML??
      I'm thinking about handling posted binary data from Flash via URLRequest.
      Java servlet can handle this, so I think CFML should be able to do something too.

      Can we??

      --Shigeru
        • 1. Re: How can we handle posted binary data??
          LeftCorner
          Have you tried the BinaryEncode() function?
          • 2. Re: How can we handle posted binary data??
            Level 7
            Shigeru@Linkcom wrote:
            > How can we handle posted binary data with CFML??
            > I'm thinking about handling posted binary data from Flash via URLRequest.

            remoting won't work?
            • 3. How can we handle posted binary data??
              Shigeru@Linkcom Level 1
              Hello.

              > Have you tried the BinaryEncode() function?
              No.
              At first I can't post ByteArray Data from Flash to ColdFusion.

              > remoting won't work?
              No.
              I convert Flex2.0 component to BitmapData, then I convert the BitmapData to ByteArray.
              And I post ByteArray via RemoteObject to ColdFusion.
              But FlashRemoting can't handle sending ByteArray. It seems like handling message eternally (never finish).

              • 4. Re: How can we handle posted binary data??
                BKBK Adobe Community Professional & MVP
                How can we handle posted binary data??
                What you want Coldfusion to do with the data? It is not clear to me what you mean by 'handle'.

                • 5. How can we handle posted binary data??
                  Shigeru@Linkcom Level 1
                  Hi.

                  > What you want Coldfusion to do with the data?
                  > It is not clear to me what you mean by 'handle'.
                  Ah, I want to save binary data as a image file.

                  1. a user paint something at FlashPlayer.
                  2. a user click "Upload" button.
                  3. as internal programming, it upload the data to ColdFusion as ByteArray.

                  Our ( FlexUserGroup at Japan ) samples is here.
                  http://cvs.sourceforge.jp/cgi-bin/viewcvs.cgi/flex2/PaintExample/

                  Java servlet ( extends HttpServlet ) can handle this.
                  So, I thought ColdFusion should handle this, but I have no idea.

                  How should I??
                  • 6. How can we handle posted binary data??
                    BKBK Adobe Community Professional & MVP
                    Two ideas


                    edited: setencoding() added




                    • 7. Re: How can we handle posted binary data??
                      Shigeru@Linkcom Level 1
                      Hi, thank you for replay and sample code.

                      I tried "cfscript" way and I got a error like below.
                      It seems like ColdFusion can't handle binary data.

                      java.lang.IllegalArgumentException
                      at javax.servlet.http.HttpUtils.parseQueryString(HttpUtils.java:149)
                      at javax.servlet.http.HttpUtils.parsePostData(HttpUtils.java:252)
                      at jrun.servlet.JRunRequest.parsePostData(JRunRequest.java:381)
                      at jrun.servlet.JRunRequest.getParameters(JRunRequest.java:361)
                      at jrun.servlet.JRunRequest.getInputStream(JRunRequest.java:239)
                      at javax.servlet.ServletRequestWrapper.getInputStream(ServletRequestWrapper.java:191)
                      at coldfusion.filter.FusionContext.getRequestContent(FusionContext.java:602)
                      at coldfusion.filter.FormScope.fillForm(FormScope.java:202)
                      at coldfusion.filter.FusionContext.SymTab_initForRequest(FusionContext.java:384)
                      at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:33)
                      at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
                      at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:115)
                      at coldfusion.CfmServlet.service(CfmServlet.java:107)
                      at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:78)
                      at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
                      at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
                      at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:257)
                      at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:541)
                      at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:204)
                      at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:318)
                      at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:426)
                      at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:264)
                      at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

                      04/21 17:09:30 error
                      java.lang.IllegalArgumentException
                      at coldfusion.filter.FormScope.parseQueryString(FormScope.java:283)
                      at coldfusion.filter.FormScope.parsePostData(FormScope.java:255)
                      at coldfusion.filter.FormScope.fillForm(FormScope.java:206)
                      at coldfusion.filter.FusionContext.SymTab_initForRequest(FusionContext.java:384)
                      at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:33)
                      at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
                      at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:115)
                      at coldfusion.CfmServlet.service(CfmServlet.java:107)
                      at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:78)
                      at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
                      at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
                      at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:257)
                      at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:541)
                      at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:204)
                      at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:318)
                      at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:426)
                      at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:264)
                      at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
                      • 8. How can we handle posted binary data??
                        BKBK Adobe Community Professional & MVP
                        Post completely revised after I discovered what might be the cause of the above error. Apparently, via the GetHttpRequestData() route, Coldfusion cannot parse the binary data when the encoding is its default UTF-8. Therefore, put this at the top of the page that contains the cfscript code:

                        <cfset setencoding("form", "UTF-16")>


                        • 9. Re: How can we handle posted binary data??
                          Shigeru@Linkcom Level 1
                          Hi, BKBK.

                          You were right.
                          "<cfset setencoding("form", "UTF-16")>" doesn't need.
                          Actually binary data is posted from ActionScript3 and the reason of taht exception is due to a URLRequest parameter.
                          "contentType " of URLRequest had to be set in case of ColdFusion (Tomcat doesn't need this).

                          Thank you for your advice!!

                          var myReq:URLRequest = new URLRequest(" http://localhost/samples/PaintExample/upload.cfm");
                          myReq.method = "POST";
                          myReq.data = data;

                          // I add this line.
                          myReq.contentType = "binary";

                          var myLoader:URLLoader = new URLLoader();
                          myLoader.addEventListener(flash.events.Event.COMPLETE,completeHandler);
                          myLoader.addEventListener(flash.events.IOErrorEvent.IO_ERROR,imgUploadIOError);
                          myLoader.addEventListener(flash.events.SecurityErrorEvent.SECURITY_ERROR,imgUploadSecurity Error);
                          myLoader.load(myReq);
                          • 10. Re: How can we handle posted binary data??
                            BKBK Adobe Community Professional & MVP
                            "<cfset setencoding("form", "UTF-16")>" doesn't need.
                            Actually binary data is posted from ActionScript3 and the reason of taht exception is due to a URLRequest parameter.
                            "contentType " of URLRequest had to be set in case of ColdFusion (Tomcat doesn't need this).


                            I was also disappointed to discover that Coldfusion includes header data like

                            -----------------------------7d6108d1304e4
                            Content-Disposition: form-data; name="FileContents"; filename="C:\Documents and Settings\Administrator\My Documents\My Pictures\MS_Sample.jpg"
                            Content-Type: image/pjpeg


                            before the actual GetHttpRequestData().content data, and

                            -----------------------------7d6108d1304e4
                            Content-Disposition: form-data; name="submit"
                            Upload File
                            -----------------------------7d6108d1304e4--


                            after it. Might be difficult to handle dynamically. I wonder if there is a neat way to remove that.

                            Thank you, too, for the useful Actionscript code.

                            • 11. Re: How can we handle posted binary data??
                              Shigeru@Linkcom Level 1
                              Hi, BKBK.

                              I'm curious to know how you dump like "... ----7d6108d1304e4 ...".
                              It's very useful information when network problem happens.

                              Could you tell us the dumping way ??
                              • 12. Re: How can we handle posted binary data??
                                BKBK Adobe Community Professional & MVP
                                Hi Shigeru,

                                The following code might work for you. However, when the content comes from an upload-form, Coldfusion includes header-information with the binary data, as I described in my previous post.

                                Version 2 requires an explanation. Christian Cantrell's article gives one.



                                • 13. Re: How can we handle posted binary data??
                                  Shigeru@Linkcom Level 1
                                  Hi, BKBK.

                                  Thank you so much!!
                                  Actually I don't try the code yet.
                                  But I'll try to figure out those code and I'll explain it at my blog in Japanese.

                                  Thanks.
                                  • 14. Re: How can we handle posted binary data??
                                    BKBK Adobe Community Professional & MVP
                                    どういたしまして。