2017-02-15 79 views
1

我正在使用Trello API将文件上传(并附加)到卡上。当附件通过API上传时,Trello附件服务错误Content-Type

我发表的帖子中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设置正确。名字也是正确的。但是,如果您从UI内部上传,则url不会像使用该文件一样。所以该文件没有.html扩展名。

当我下载的文件,它包含了这个头

Content-Type: application/octet-stream 

它应该是text/html的。这会导致浏览器下载文件而不是显示它。

我做错了什么?有没有其他人有这个问题?

此外,有什么办法让Trello在构建url时使用文件名?

回答

0

当我附上一个文件或URL到Trello卡,我用POST只有url,像这样(的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。您可以看到nameurl相同,但在此处没有mimeType。在the documentation中找不到它。你是以哪种方式获取卡数据?如果您使用JavaScript,上面的代码可能会对您有所帮助。

至于定制卡的网址,我什么都不知道,我想这是不可能的。

0

{文件:file_contents, 'BuildSheet.html':文件名,mime类型: 'text/html的'}

您是否尝试过使用该密钥namereference