我正在从Drupal网站(与Podio PHP客户端)一起使用Podio API。使用该文件,可以上传几种类型的文件(我从自定义Web表单允许的所有文件)并附加到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会将应用程序/八位字节流MIME类型分配给.msg文件,这是无法识别的每种自定义文件类型的常规MIME类型。 MIME类型实际上应该是application / vnd.ms-outlook。
Podio API不允许使用MIME类型为application / octet-stream(https://developers.podio.com/doc/files)的文件。
但是在将.msg文件映射到正确的MIME类型之后,Podio仍然不允许它。
答案 0 :(得分:0)
通过url上传文件是内部方法,这就是为什么它无法通过任何外部调用工作的原因。
请使用“上传文件”方法https://developers.podio.com/doc/files/upload-file-1004361
您可以在以下位置找到所有受支持的文件操作:https://developers.podio.com/doc/files
答案 1 :(得分:0)
要上传文件,您应该使用Podio php Client中提供的以下方法:
PodioFile::upload( $file_path, $file_name );
其中$file_path
是文件的路径,而$file_name
是文件的名称。
注意:请求期望请求正文为multipart / form-data
有关更多信息,请参见here。
谢谢!