我可以使用Google Drive API上传受密码保护的PDF吗?

时间:2018-10-22 12:07:39

标签: php google-drive-api google-api-php-client

因此,我尝试上传普通的不受密码保护的pdf文件,并使用以下代码成功上传了该文件。 但是,如果我尝试使用受密码保护的文件,则Google会抛出400错误代码(错误请求) 参考:https://developers.google.com/drive/api/v3/reference/files/create

 $content = file_get_contents($file_path);
 $fileMetadata = new Google_Service_Drive_DriveFile(array(
                        'name' => 'dummy_name',
                        'mimeType' => 'application/vnd.google-apps.spreadsheet'));

 $file = $service->files->create($fileMetadata, array(
                        'data' => $content,
                        'mimeType' => 'application/pdf',
                        'uploadType' => 'multipart',
                        'fields' => 'id'));

即使我拥有密码,是否可以上传带有密码保护的pdf?

1 个答案:

答案 0 :(得分:0)

您似乎已将mimeType设置为“ application / vnd.google-apps.spreadsheet”。 我认为如果将其设置为“ application / pdf”,它应该可以工作

就我而言,受密码保护的文件上传似乎适用于PDF,但不适用于DOCX文件。