我可以上传.docx文件,以谷歌从我的应用程序驱动,但是当我试图上传.doc文件,这个错误出现了:无法上传与谷歌驱动器的SDK .doc文件
发生错误:错误调用POST https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&key=AIzaSyCm1WqPp05lBRjKSpxdtHjS8lz6WLeoWlU:(400)提供的无效MIME类型
当我上载.ppt .xls文件时,也出现了该错误。该文件表示我们可以在Google云端硬盘中存储任何MIME类型。这里有什么问题?有人知道吗?
这是我上传功能:
function insertFile($title, $description, $parentId, $mimeType, $filename) {
$file = new DriveFile();
$file->setTitle($title);
$file->setDescription($description);
$file->setMimeType($mimeType);
if ($parentId != null) {
$parent = new ParentReference();
$parent->setId($parentId);
$file->setParents(array($parent));
}
try {
$data = file_get_contents($filename);
$createdFile = $this->service->files->insert($file, array(
'data' => $data,
'mimeType' => $mimeType,
));
return $createdFile;
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}
[更新]我用CI,这是我在控制器功能调用的insertFile功能:
function upload() {
$title = $this->input->post('title');
$description = $this->input->post('description');
$parentId = $this->input->post('parentId');
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
$driveHandler = new DriveHandler($_SESSION['credentials']);
$driveHandler->BuildService($_SESSION['credentials']);
$ext = substr(strrchr($_FILES["file"]["name"],'.'),1);
if($title === ""){
$fileTitle = $_FILES["file"]["name"];
} else {
$fileTitle = "$title.$ext";
}
$driveHandler->insertFile($fileTitle, $description, $parentId, $_FILES["file"]["type"], $_FILES["file"]["tmp_name"]);
}
'$ mimeType'等于什么? – doublesharp
$ mimeType = $ _FILES [“file”] [“type”]。在我看来,我有这个:form_upload('file'); – Irien
不,失败时的实际值 - 错误是抱怨MIME类型。 – doublesharp