我正在尝试使用 php asana 库(https://github.com/Asana/php-asana)向任务添加附件。我成功地“添加”了文件,但是当我在任务中打开它们时,它们完全为空或损坏。
我试过 .png、.doc 和 .pdf 都得到相同的结果。我的请求如下所示:
$attachment = $client->attachments->createOnTask(
$task->id,
'screenshot_from_2016-07-08_140457.png',
'http://edit.local.org/sites/default/files/webform/change-request-materials/screenshot_from_2016-07-08_140457_8.png',
'image/png'
);
我也尝试过使用文件名的相对路径,/sites/default/files/webform/change-request-materials/screenshot_from_2016-07-08_140457_8.png
但得到了相同的结果。
这是我从库中使用的“示例代码”,看起来很简单。
// add an attachment to the task
$demoAttachment = $client->attachments->createOnTask(
$demoTask->id,
"hello world",
"upload.txt",
"text/plain"
);
还尝试在https://asana.com/developers/api-reference/attachments中使用 2 个版本的 curl 请求,以查看是否可以让附件正常工作。
第一:
curl -H "Authorization: Bearer <personal_access_token>" https://app.asana.com/api/1.0/tasks/152938418205845/attachments --form "file=@http://edit.local.org/sites/default/files/webform/change-request-materials/screenshot_from_2016-07-08_140457_12.png;type=image/png"
导致
curl: (26) couldn't open file "http://edit-fca.local.org/sites/default/files/webform/change-request-materials/screenshot_from_2016-07-08_140457_12.png"
我在文件和文件所在的文件夹上有 777。所以我决定删除文件前面的“@”,然后得到:
{"errors":[{"message":"file: File is not an object","help":"For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"}]}
当我访问那个 URL 时,它并没有真正告诉我关于文件不是对象错误的任何信息。
有点卡住,因为 php-asana 库似乎至少将文件放在那里,但它们是空的。虽然 curl 请求似乎根本不起作用。
顺便说一句,我使用的是 php 5.5.9。