【问题标题】:Google API PHP Update File谷歌 API PHP 更新文件
【发布时间】:2015-02-18 08:22:02
【问题描述】:

我正在尝试更新文件的内容。使用PHP函数:

function updateFile($service, $fileId, $newTitle, $newDescription, $newMimeType, $newFileName, $newRevision) {
    try {
        // First retrieve the file from the API.
        $file = $service->files->get($fileId);

        // File's new metadata.
        $file->setTitle($newTitle);
        $file->setDescription($newDescription);
        $file->setMimeType($newMimeType);

        // File's new content.
        $data = file_get_contents($newFileName);

        $additionalParams = array(
            'newRevision' => $newRevision,
            'data' => $data,
            'mimeType' => $newMimeType
        );

        // Send the request to the API.
        $updatedFile = $service->files->update($fileId, $file, $additionalParams);
        return $updatedFile;
    } catch (Exception $e) {
        print "An error occurred: " . $e->getMessage();
    }
}

....
$data = retrieveAllFiles($service);


$fileName = 'test.txt';
$mimeType = mime_content_type('./'.$fileName);


$res = updateFile($service, $data[0]['id'], $data[0]['title'], 'update', $mimeType, $fileName, true);

我正在尝试添加一个文本文件行“测试字符串”。函数更新数据文件(description、lastModifyingUser...),但文件内容保持不变。谁能告诉我怎么了?

【问题讨论】:

标签: php google-app-engine google-drive-api


【解决方案1】:

在额外的Params中需要添加:

'uploadType' => 'multipart',
or 
'uploadType' => 'media',

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-24
    • 2012-06-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多