通过 Monday.com API 使用 ColdFusion 添加文件时出现问题
我一直在使用 Monday API,并在使其准备好在我们的系统和我们使用的其他一些工具中可用方面取得了很大进展,但是,当涉及到它时,我遇到了一些障碍添加文件。我已经能够做其他所有事情,从添加项目、更新、专栏、看板到阅读我需要的内容,但添加文件最终让我崩溃。我的代码基于 将文件上传到 monday.com,困难的方式。作者使用的是 NodeJS,所以我尽力对其进行转换。 我的代码如下:
<cfset dataQuery = 'mutation ($file:File!) {add_file_to_column (item_id: 123456789, column_ID: file, file: $file){id}}'>
<cfset boundary = "xxxxxxxxxx">
<cfset upfile = "image1.png">
<cfset base64Sample = SAMPLE_BASE64_STRING>
<cfset data = "">
<!--- Construct Query --->
<cfset data &= "--" & boundary & "#chr(13)##chr(10)#">
<cfset data &= 'Content-Disposition: form-data; name="query"#chr(13)##chr(10)##chr(13)##chr(10)#'>
<cfset data &= dataQuery & '#chr(13)##chr(10)#'>
<cfset data &= "--" & boundary & "#chr(13)##chr(10)#">
<!--- Construct File --->
<cfset data &= 'Content-Disposition: form-data; name="variables[file]"; filename="' & upfile & '";#chr(13)##chr(10)#'>
<cfset data &= "Content-Type:application/octet-stream;#chr(13)##chr(10)##chr(13)##chr(10)#">
<cfset data &= ToString(ToBinary(base64Sample))>
<cfset data &= "#chr(13)##chr(10)#--" & boundary & "--#chr(13)##chr(10)#">
<cfdump var="#data#">
<cfhttp method="post" url="https://api.monday.com/v2" result="result">
<cfhttpparam type="Header" name="Content-Type" value="multipart/form-data; boundary=#boundary#">
<cfhttpparam type="Header" name="Authorization" value="#mondayLogin.Token#">
<cfhttpparam type="body" value="#data#">
</cfhttp>
当我试图让它工作时,格式已经发生了一些变化,但无论我做什么,它总是给我相同的错误消息:“不存在查询字符串”。
我希望这里对多部分边界和 Monday API 有更多了解的人可以提供帮助。
编辑:我将 \r\n
更改为 chr(13)chr(10)
,但仍然遇到相同的错误。
编辑 2:经过更多的重构后,我似乎已经克服了第一个错误,现在我遇到了 2 个与 GraphQL 相关的新错误,我认为。
- 字段“add_file_to_column”缺少必需参数:column_id
- 字段“add_file_to_column”不接受参数“column_ID” 我确信我仍然在某个地方格式化错误,但我还不知道那在哪里。
编辑3:原来我的列名是错误的。 “ID”不应大写,而应为“column_id”。我现在收到另一个新错误:内部服务器错误 (500)
I’ve been playing with the Monday API and have made a lot of progress towards getting it ready to be available in our system and a couple of other tools we use, however, I’ve hit a bit of a snag when it comes to adding files. I’ve been able to do everything else from adding items, updates, columns, boards and reading what I’ve needed, but adding files is what has finally broken me. I’m basing my code off of Uploading a file to monday.com, the hard way. The author is using NodeJS so I’ve tried to convert it as best I can.
My code below:
<cfset dataQuery = 'mutation ($file:File!) {add_file_to_column (item_id: 123456789, column_ID: file, file: $file){id}}'>
<cfset boundary = "xxxxxxxxxx">
<cfset upfile = "image1.png">
<cfset base64Sample = SAMPLE_BASE64_STRING>
<cfset data = "">
<!--- Construct Query --->
<cfset data &= "--" & boundary & "#chr(13)##chr(10)#">
<cfset data &= 'Content-Disposition: form-data; name="query"#chr(13)##chr(10)##chr(13)##chr(10)#'>
<cfset data &= dataQuery & '#chr(13)##chr(10)#'>
<cfset data &= "--" & boundary & "#chr(13)##chr(10)#">
<!--- Construct File --->
<cfset data &= 'Content-Disposition: form-data; name="variables[file]"; filename="' & upfile & '";#chr(13)##chr(10)#'>
<cfset data &= "Content-Type:application/octet-stream;#chr(13)##chr(10)##chr(13)##chr(10)#">
<cfset data &= ToString(ToBinary(base64Sample))>
<cfset data &= "#chr(13)##chr(10)#--" & boundary & "--#chr(13)##chr(10)#">
<cfdump var="#data#">
<cfhttp method="post" url="https://api.monday.com/v2" result="result">
<cfhttpparam type="Header" name="Content-Type" value="multipart/form-data; boundary=#boundary#">
<cfhttpparam type="Header" name="Authorization" value="#mondayLogin.Token#">
<cfhttpparam type="body" value="#data#">
</cfhttp>
The formatting has gotten shifted a little bit as I tried to get it working but no matter what I do, it always gives me the same error message: “No query string was present”.
I’m hoping someone here who has more knowledge about doing multi-part boundaries and the Monday API can help.
Edit: I changed the \r\n
to the chr(13)chr(10)
and am still getting the same error.
Edit 2: After a little more refactoring on it I seem to have gotten past the first error and now I've hit 2 new one that are related to GraphQL I think.
- Field 'add_file_to_column' is missing required arguments: column_id
- Field 'add_file_to_column' doesn't accept argument 'column_ID'
I'm sure I'm still formatting it wrong somewhere but I don't see where that is yet.
Edit 3: Turns out my column name was wrong. The 'ID' shouldn't have been in caps but should be 'column_id'. I'm now getting another new error of: Internal server error (500)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我遇到了很多问题,有很多不同的错误消息。基本上我有 3 个问题:
\r\n
替换为chr(13)chr(10)
的正确 ColdFusion 值So I ran into MANY issues on this with a lot of different error messages. Basically I had 3 issues:
\r\n
with the correct ColdFusion values ofchr(13)chr(10)