Adding File to Column With ColdFusion

I’m at my wits end here. This api has been so frustrating with adding files I’m close to quitting. It’s bee one issue after another. I’ve been unable to add a file using the multi part method for months now. I’m out of ideas.

My current code is this:

<cfset storedFileName = "test.png">
<cffile action="read"	file="f:\TempFiles\#storedFileName#"	variable="TempFile">

<cfset thisData = "">
<cfsavecontent variable="thisData">
--xxxxxxxxxx
Content-Disposition: form-data; name="query"

mutation ($file:File!) {add_file_to_column (item_id: ITEM_ID_HERE, column_id: "files", file: $file){id}}

--xxxxxxxxxx
Content-Disposition: form-data; name="variables[File]"; filename="f:\TempFiles\image1.png"
Content-Type:application/octet-stream

<cfoutput>#TempFile#</cfoutput>
--xxxxxxxxxx--
</cfsavecontent> 

<cfhttp method="post" url="https://api.monday.com/v2/file" result="result">
	<cfhttpparam type="Header" name="Authorization"  value="MONDAYTOKEN">
	<cfhttpparam type="Header" name="Content-Type" value="multipart/form-data; boundary=xxxxxxxxxx">
	<cfhttpparam type="body" value="#thisData#">
</cfhttp>

This is my payload that’s being sent.

--xxxxxxxxxx
Content-Disposition: form-data; name="query"

mutation ($file:File!) {add_file_to_column (item_id: ITEM_ID_HERE, column_id: "files", file: $file){id}}

--xxxxxxxxxx
Content-Disposition: form-data; name="variables[File]"; filename="f:\TempFiles\image1.png"
Content-Type:application/octet-stream

‰PNG


IHDRàw=øsBIT|dˆ	pHYs¦¦Ý}ÿ8tEXtSoftwarewww.inkscape.org›î<BIDATH‰µ–OleEÆ3»›]Û]o\R'¢”©É%Tò V¨ TªŠ(HTŠP§"è¡ õ‡öJ/ z!T	$"„ÔCEŽp q¤†ªÄŸpNǍíØYïaãØ›Æñfö{û½÷fÞ{»BkMÇßzAXúu3ØÖкïë2hòå[IÇ/D¬fÕhh_|˜ºñޗa:¢í`ñ…¨Yq†ì«Ïeї•Ï§[
ݧVˆ=Y ú]‚µo÷o’¯$íÚçKçps_½º~½¶é 8~é9%Ā‹ÔËÒ֞Z—fg4¯-pï£C]‘ʈjª†(£ÄCÀšÔú¥äk_‹Åñ·Ÿu°BÏjöŸ/°òÙÐn¦>È1Tºq!{±Ú„*m"„˽]Œ~sM¯ „+µ`Š<ô
֑‘	èe¬÷ ®µLÉÔåù;›yôx9t½Ü+*uyþŽÄ²±Ìªáž\F˜á‰8Üc•öÇ*8ÕP[ajܓËÄ2«~5*ƒÄÒ«ØGªT§4棨ª€á6ñN-u	y§–ðÁZ«še,À>\#–+a&Úw¥2&J¤­½™ðñƊøE›_¢X¬#ìî¶Â;ó'þoú«a%eÝé(‘:ö.
Í÷¿cqo•ý/ Ñäÿ7uMÞDêY´8ÛɽÿÉ4?ýZ"wè÷^„„çP*×)•×Y-×)ݯsôÑoNäBÂ׳&ZæÃÚr¡P¦ZÛ ZÛà÷?î?0ЅÂ}¡e^b3€ßÉ
x h¶>–1#,¢ÅÕNöÜé⮽«xܵ9wz¤›ú
£“ÅV‰‡¯s[ùþ¸Ãʼnaab;Šˆqq"GÜé¤æЃW[~ÚsnæÌq¤1MÇèn6SßüÌ?.±p·uև=F?À³OÁ4»*ÝG9²7oow0ûüeÀµN'{€\"ýÕaía¢ë£ßÊäcà‰=ŠÏ¡‚Wۑ·ÑÝÉٛ·!•E‹w	©®Ð¨…~aRÙNqË`+¾1‰d*ó÷PÜümi5¨Ìc3ŒNw’ø#3ú7ïÕIEND®B`‚
--xxxxxxxxxx--

This gives me this error:
image

I had what I though a working method when I posted this thread a while ago but upon checking and validating files further it wasn’t working. Here is that post (Problem adding files with ColdFusion via API)

That would give me a success message but in reality it would add a corrupted file.
image

If anyone can help I’d really appreciate it. I’ve looked at the following sources for help and can’t seem to get over this issue.
Announcement
Node JS example
Adding file to column via API

Hello there @jWilde!

Would you be able to transform this into cURL and send it to me?

Maybe you can use a software like Postman for this.

Looking forward to hearing from you :slightly_smiling_face:

Cheers,
Matias

I don’t see how changing it to cURL would help. It’s an issue with how to get it to work with coldfusion.

Hello again @jWilde I did not know that this was using coldfusion from Adobe.

I was asking for the cURL to take a look into it but I have no experience with coldfusion.

Hope someone in the community has experience with it!

I’m adding this here so others facing this issue can have a working example. This problem has caused me months of stimming.

I can’t explain why it works or all the ins and outs of it, but it worked. I found it on StackOverflow.

<cfscript>
    postURI = "https://api.monday.com/v2/file";
    filePath = "f:\TempFiles\TestFile.png";
    payload = 'mutation ($file: File!) { add_file_to_column (file: $file, item_id: ID_GOES_HERE, column_id: "files") {id} }';
    mondayToken = "TOKEN_GOES_HERE";
 
    method = createObject("java", "org.apache.commons.httpclient.methods.PostMethod").init( postURI );
    
    try {
        // add auth header
        method.addRequestHeader("Authorization", mondayToken);

		// add query field
        jsonPart = createObject("java", "org.apache.commons.httpclient.methods.multipart.StringPart").init(
            "query"
            , payload
        );
    
        // Set the content-type to "application/json"
        jsonPart.setContentType("application/json");

        // add "variables[file]" field
        filePart = createObject( "java", "org.apache.commons.httpclient.methods.multipart.FilePart").init(
            "variables[file]"  
            , "myFile.png"
            , createObject( "java", "java.io.File").init( filePath )
        );

        // construct request data     
        requestEntity = createObject( "java", "org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity").init(
            [ jsonPart, filePart  ]
            , method.getParams()
        );
    
        method.setRequestEntity( requestEntity );
        
        // submit and display response
        status = createObject('java', 'org.apache.commons.httpclient.HttpClient').init().executeMethod( method );
        body = method.getResponseBody();
        writeOutput( charsetEncode(body, "utf-8"));
    
    }
    finally {
        method.releaseConnection();
    }
</cfscript>
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.