我正在使用Trello API将文件上传(和附加)到卡上。
我在https://api.trello.com/1/cards/my-card-id/attachments上发了一个帖子
消息正文为JSON
{ file: file_contents, 'BuildSheet.html': filename, mimeType: 'text/html' }
file_contents is a string that contains the body of the file I want to attach.这是可行的。文件将上载并附加。当我获取卡数据时,这就是我看到的关于这个附件的内容。
{"id":"58a496bc751c0c2fa260630f",
"bytes":3291,
"date":"2017-0215T17:58:20.881Z",
"edgeColor":null,
"idMember":"55240806b8ca85db897253c4",
"isUpload":true,
"mimeType":"text/html",
"name":"BuildSheet.html",
"previews":[],
"url":"https://trello-attachments.s3.amazonaws.com/589ca323806c1d80cc03ea12/589ceda619d5936e8428f15b/1f62074b6700e61e611a90beaa8c2c73/Upload"}您可以看到mimeType设置正确。名字也是正确的。但是,url并不像从UI内部上传那样使用文件名。因此该文件没有.html扩展名。
当我下载该文件时,它包含以下标头
Content-Type: application/octet-stream它应该是text/html。这会导致浏览器下载该文件,而不是显示它。
我做错了什么吗?其他人也有这个问题吗?
另外,有没有办法让Trello在构建url时使用文件名?
发布于 2019-11-06 08:42:45
Trello API似乎忽略了mimeType参数,而是在响应体中使用Content-Disposition参数。
如下所示的实体工作:
------WebKitFormBoundarydjg0lJJiuTZmCppw
Content-Disposition: form-data; name="file"; filename="image.png"
Content-Type: image/png下面是使用节点请求库的相应代码:
async function attachFileToTrelloCard(id: string, file: Buffer, fileName: string, mimeType: string) {
const options = {
method: 'POST',
url: `https://api.trello.com/1/cards/${id}/attachments`,
formData: {
file: {
value: file,
options: {
filename: fileName,
contentType: mimeType
}
},
token: process.env.TRELLO_API_TOKEN,
key: process.env.TRELLO_API_KEY,
name: fileName,
mimeType
}
}
return await request(options)
}发布于 2017-03-04 12:59:00
当我将文件或url附加到Trello卡上时,我只对url使用POST,如下所示(JavaScript):
var id = 'something';
var attach = 'https://www.cs.tut.fi/~jkorpela/forms/file.html';
var payload = {"url": attach};
var blob = new Blob([JSON.stringify(payload)], {type: 'application/json'});
var url = 'https://api.trello.com/1/cards/'+id+'/attachments?key='+API_KEY+'&token='+TOKEN;
var xhttp = new XMLHttpRequest();
xhttp.open("POST", url, true);
xhttp.send(blob);在此之后,当我获得卡的JSON时,它是这样的:
{"id":"xxx...", ...
"actions":[{
"id":"yyy...",
"idMemberCreator":"...",
"data":{
"board":{ ...
"attachment":{
"url":"https://www.cs.tut.fi/~jkorpela/forms/file.html",
"name":"https://www.cs.tut.fi/~jkorpela/forms/file.html",
"id":"zzz..."}}, ...您可以通过在url末尾添加.json来获取卡片的JSON。你可以看到name和url是一样的,但是这里没有mimeType。在the documentation中找不到它。您是通过哪种方式“获取卡数据”的?如果您使用JavaScript,上面的代码可能会对您有所帮助。
至于定制卡片的网址,我什么都不知道,我猜这是不可能的。
发布于 2017-03-14 18:06:15
{文件: file_contents,'BuildSheet.html':文件名,mimeType:'text/html‘}
您尝试过使用密钥name吗?reference
https://stackoverflow.com/questions/42257159
复制相似问题