Skip to main content
Known Participant
July 29, 2010
Question

Help! need to get a binary image from an http request and write to file

  • July 29, 2010
  • 2 replies
  • 4946 views

First a little background,  I'm creating a virtual webdav server in CF that will allow me to create a repository to store comments from an acrobat Shared Review (webdav).  I have iis intercepting the webdav verbs and passing them on to my CF template which then responds appropriately using cfheader and cfcontent tags.  Everything is working great, except for the custom stamps.  The custom stamps don't display properly (i get a stamp with no image inside of it).  I'm using GetHttpRequestData() and <cffile action="write"> to write the content of the request to a file.  but when i compare the saved file's contents with the contents of the same image saved over true webdav, there are slight differences in some of the characters that should not exist.  If i have the template to respond with the file that was saved via true webdav, the image displays properly.  So it seems that CF is making some very slight alterations to the http content before or during saving.  I've played around with the encoding but that didn't seem to help.  I have used a packet monitor to verify that acrobat is sending exactly the same data to both CF and true webdav, but the file saved via CF is altered.  Does anyone have any suggestions on what I could try?

    This topic has been closed for replies.

    2 replies

    Participating Frequently
    October 9, 2010

    I am trying to do this VERY thing!  I am using IIS7 and have installed the IIS Rewrite 2.0 Plugin but I don't have a clue how to configure it to rewrite my PUT requests to add a content-type header if one is missing.  Can anyone help me out?

    --Stewart McGuire

    Inspiring
    July 29, 2010

    The first thing I recommend is to post some code demonstrating what you're seeing. We'll have to make some assumptions about what IIS is doing with the requests before passing to CF, but as you say it sounds like that part is working OK.

    Can you also post a copy of all the HTTP headers for an example request.

    --

    Adam

    Known Participant
    July 29, 2010

    I'm using an ISAPI filter in IIS to rewrite the url to a coldfusion template.  That part is working great.

    My code for the PUT verb looks like this:

    <cfset HttpRequestData = GetHttpRequestData()>
    <cfset RequestContent =  HttpRequestData.content>
    <cffile action="write" file="MyFile.bin" output="#RequestContent#" addNewLine="no" fixnewline="no">

    The Http request looks like this:


    PUT /secure/data/projects/proj_109/annotations/001CFDavThurs1.pdf__aa2e6c6df6604c4d9ae927022427386d/attachments/0-55d287db-c9e5-438d-b5cb-6b94ac123c58.bin HTTP/1.1
    Accept: */*
    User-Agent: Mozilla/3.0 (compatible; Adobe Synchronizer 10.0)
    Host: 68.2.42.213
    Content-Length: 2427
    Connection: Keep-Alive

    %CSO-1.0%
    1 0 obj<</- 2 0 R/Type/Catalog>>endobj2 0 obj<</BBox[12.0 12.0 60.0 60.0]/Filter[/FlateDecode]/FormType 1/Length 39/Matrix[1.0 0.0 0.0 1.0 -12.0 -12.0]/Name/FRM/Resources<</ProcSet[/PDF/ImageC]/XObject<</Im0 3 0 R>>>>/Subtype/Form/Type/XObject>>stream
    H**B RF k
    endstreamendobj3 0 obj<</BitsPerComponent 8/ColorSpace/DeviceRGB/Filter/DCTDecode/Height 48/Length 1226/Name/X/SMask 4 0 R/Subtype/Image/Type/XObject/Width 48>>stream
    Adobed$''''$25552;;;;;;;;;;


    ####''',,,00"B

    3!1AQa"q2B#$Rb34rC%Scs5&DTdEt6UeuF'Vfv7GWgw;!1AQaq"2B#R3$brCScs4%&5DTdEU6teuFVfv'7GWgw?I%)i^7pT$ho<Ep)p\r{tW-1q`#}<Kp;,R<-t}pqt.xNm0O}W{se%;`@+1(r3:Yts"R$
    5nkXp/k5x*))7Zgz;i\!lpllpx0u])f~Q6t{Y'ljK,o8h1>K#fh.!t69fUECd}:)kZ4!v[.]Xs6 k|H>VkfWRuu48*+~b!33
    57VYmNs8q3Hgh<FUwOz{|,tG~B>}m~qqc1C0Fi:gY~vs51y`3F<~^%I$
    endstreamendobj4 0 obj<</BitsPerComponent 8/ColorSpace/DeviceGray/Filter/FlateDecode/Height 48/Length 366/Name/X/Subtype/Image/Type/XObject/Width 48>>stream
    HK1Q:Aussp]8RqTA:V `sa8n$.g?z[LxW\{A|%7)`'@)
    *@aep|2?CQWuws{6n<5V{=q{S
    Rzkd/=j./i])H`WIED?-cQmw"6I6//[,2k$:uvM>M{VG-3<z]4_Zlz0WPMyayhIaKq`Z`b
    endstreamendobjxref
    0 5
    0000000000 65535 f
    0000000016 00000 n
    0000000057 00000 n
    0000000331 00000 n
    0000001730 00000 n
    trailer
    <</Size 5/Root 1 0 R>>
    startxref
    2259
    %%EOF

    Known Participant
    July 29, 2010

    After some research and creating some output tests, I believe that my problem is that acrobat does not specify a content-type in the PUT request header.  Therefore CF seems to be casting it from binary to text:

    From the CF documentation

    ColdFusion recognizes the response body as text if:

    • the header does not specify a content type.
    • the content type starts with "text".
    • the content type starts with "message".
    • the content type is "application/octet-stream".

    Does anyone know how to prevent coldfusion from converting the content or how to get it back into its original state?  ToBinary(ToBase64(MyVariable)) gets close but ends up corrupting the original data (which prevents the image from displaying).