无法使用PHP SDK将多个文件上传到Google云端硬盘

时间:2013-11-18 19:31:13

标签: google-app-engine file-upload google-drive-api

我正在尝试使用PHP SDK将多个文件上传到Google云端硬盘。为此,我调用下面的函数迭代地传递所需的参数:

function insertFile($driveService, $title, $description, $parentId, $fileUrl) {
    global $header;

    $file = new Google_DriveFile();
    $file->setTitle($title);
    $file->setDescription($description);
    $mimeType= "application/vnd.google-apps.folder";

    if ($fileUrl != null) {
      $fileUrl = replaceSpaceWithHtmlCode($fileUrl);
      $header = getUrlHeader($fileUrl);
      $mimeType = $header['content-type'];
    }
    $file->setMimeType($mimeType);
    $parent = new Google_ParentReference();
    // Set the parent folder.
    if ($parentId != null) {
      $parent->setId($parentId);
      $file->setParents(array($parent));
    }

    try {
      $data = null;
      if ($fileUrl != null) {
        if (hasErrors($driveService, $fileUrl) == True) {
          return null;
        }
        $data = file_get_contents($fileUrl);
    }

    $createdFile = $driveService->files->insert($file, array(
      'data' => $data,
      'mimeType' => $mimeType,
    ));

      return $createdFile;
    } catch (Exception $e) {
        echo "Error: 12";
    return null;
    }
}

我在Google App Engine上运行此应用程序。

但是,我无法上传传递给它的所有文件。例如,如果我传递大约12-15个文件,只有10-11个上传,有时都会上传,即使所有参数都正确。当它无法创建文件时我已经捕获了异常,并且这表示它无法为未上载的文件创建文件。我在应用引擎的日志中看不到任何警告或错误。

我错过了什么吗?有人可以指出我应该在哪里纠正这个问题并使其足够可靠,以便上传给它的所有文件吗?

我尝试上传30个文件时收到的HTTP响应是:

PHP Fatal error:  The request was aborted because it exceeded the maximum execution time

1 个答案:

答案 0 :(得分:0)

检查http响应以查看详细原因。可能是您达到了油门限制并获得403限速响应。

相关问题