【发布时间】:2019-12-09 03:00:37
【问题描述】:
我正在使用 Drupal 网站上的 Podio API(带有 Podio PHP 客户端)。使用它可以上传几种类型的文件(我允许的所有来自自定义网络表单的文件)并附加到 Podio 项目,没有任何问题。
似乎无法上传的唯一文件是 .msg 文件。在上传 .msg 文件时,会收到以下消息:
PodioBadRequestError: PodioBadRequestError in Podio::request()
这对我没有多大帮助。
.msg 文件似乎也没有在此处排除:https://developers.podio.com/doc/files
是否可以使用 Podio API 上传 .msg 文件,如果可以,有人知道我做错了什么吗?
提前致谢。
更新
我用来将项目发布到 Podio 的一些代码
PodioIncidentItem:这是发布到 Podio 的项目
/**
* Post incident to Podio
*/
public function postToPodio() {
$podioConnection = new PodioAPIConnection();
$podioConnection->setupAndAuthenticate();
if(!$this->podio_link_available) {
$this->incident_description = t('Ticket by: ' . $this->requested_by . '<br /><br />' . $this->incident_description);
$this->requested_by = NULL;
}
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array(
"external_id" => "title",
"values" => $this->short_title,
)),
new PodioAppItemField(array(
"external_id" => "username",
"values" => array((int)$this->requested_by),
)),
new PodioAppItemField(array(
"external_id" => "sdt-user",
"values" => array((int)$this->sdt_user),
)),
new PodioCategoryItemField(array(
"external_id" => "contactmethod",
"values" => (int)$this->contactmethod,
)),
new PodioTextItemField(array(
"external_id" => "text",
"values" => $this->incident_description,
)),
new PodioAppItemField(array(
"external_id" => "catalog-selection",
"values" => array((int)$this->catalog_selection),
)),
new PodioCategoryItemField(array(
"external_id" => "urgency",
"values" => (int)$this->urgency,
)),
new PodioCategoryItemField(array(
"external_id" => "impact",
"values" => (int)$this->impact,
)),
new PodioCategoryItemField(array(
"external_id" => "status",
"values" => (int)$this->status,
)),
new PodioCategoryItemField(array(
"external_id" => "source-ticket",
"values" => (int)$this->source_ticket,
)),
));
$item = new PodioItem(array(
'app' => new PodioApp((int)$this->config->get('podioapi.incidents_app_id')),
'fields' => $fields
));
// Save the new item
$response = $item->save();
// Add the uploaded files to the Podio item
foreach($this->fids as $fid) {
$file = File::load($fid);
$file_name = $file->getFilename();
$uri = $file->getFileUri();
$base_url = file_create_url("public://");
$uri_resolved = str_replace('public://', '', $uri);
$url = $base_url . $uri_resolved;
$upload_result = PodioFileExtended::uploadFromURL($url);
$file_id = $upload_result->file_id;
$attributes = array('ref_type' => 'item', 'ref_id' => $response->item_id);
PodioFile::attach($file_id, $attributes);
}
return $response;
}
PodioFileExtended:Podio PHP API PodioFile 类的扩展版本,该类被扩展以启用从 URL 选项上传
/**
* @see https://developers.podio.com/doc/files
*/
class PodioFileExtended extends PodioObject {
public function __construct($attributes = array()) {
$this->property('file_id', 'integer', array('id' => true));
$this->property('link', 'string');
$this->property('perma_link', 'string');
$this->property('thumbnail_link', 'string');
$this->property('hosted_by', 'string');
$this->property('name', 'string');
$this->property('description', 'string');
$this->property('mimetype', 'string');
$this->property('size', 'integer');
$this->property('context', 'hash');
$this->property('created_on', 'datetime');
$this->property('rights', 'array');
$this->has_one('created_by', 'ByLine');
$this->has_one('created_via', 'Via');
$this->has_many('replaces', 'File');
$this->init($attributes);
}
/**
* @see https://developers.podio.com/doc/files/upload-file-1004361
*/
public static function uploadFromURL($url) {
return self::member(Podio::post("/file/from_url/", array('url' => $url)));
}
}
更新 2
我们在此期间发现的更多信息
开箱即用的 Drupal 将 application/octet-stream MIME 类型分配给 .msg 文件,这是每个无法识别的自定义文件类型的通用 MIME 类型。 MIME 类型实际上应该是 application/vnd.ms-outlook。
Podio API 不允许 MIME 类型为 application/octet-stream (https://developers.podio.com/doc/files) 的文件。
但在将 .msg 文件映射到正确的 MIME 类型后,Podio 仍然不允许。
【问题讨论】:
-
您可以通过 Podio UI 上传该文件吗?
-
嗨,是的,我们可以通过 Podio UI 上传 .msg 文件
-
那么,请提供您尝试过的代码。谢谢。
-
嗨@MûhámmàdYäsårK,很抱歉我的回答延迟了,我已经用相关代码更新了我的问题
-
能否提供请求和响应的网络跟踪信息?