【问题标题】:Resumable upload using Google Client API . Invalid Upload URL使用 Google Client API 可恢复上传。上传网址无效
【发布时间】:2017-08-21 02:46:26
【问题描述】:

我无法使用此 api 执行可恢复上传,请帮助我。此代码工作正常,直到我使用可恢复上传。我可以使用 Multipart 上传文件,但不能使用 multipart 上传大文件

我的代码

            $storageObject->setName("FIle Name.mp3");
            $storageObject->setBucket($data["bucket_name"]); 
            $mimetype = mime_content_type($data["temp_name"]);

            $chunkSizeBytes = 1 * 1024 * 1024;

            $storageClient->setDefer(true);

            $status = false;

            $filetoupload = array('name' => "FIle Name.mp3", 
           'uploadType' => 'resumable');

            $request = $storageService->objects->insert(
            $data["bucket_name"], $storageObject, $filetoupload );

            $media = new Google_Http_MediaFileUpload($storageClient,
            $request, $mimetype, null, true, $chunkSizeBytes);

            $media->setFileSize(filesize($data["file_temp_name"]));
            $handle = fopen($data["file_temp_name"], "rb");

            while (!$status && !feof($handle)) 
            {
               $chunk = fread($handle, $chunkSizeBytes);
               $status = $media->nextChunk($chunk);
            }

            $result = false;
            if($status != false) {
            $result = $status;
            }


            $storageClient->setDefer(false);

响应错误

      {
      "error": {
        "errors": [
        {
      "domain": "global",
          "reason": "wrongUrlForUpload",
       "message": "Upload requests must include an uploadType URL parameter and a URL path beginning with /upload/",
       "extendedHelp": "https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload"
      }
     ],
     "code": 400,
      "message": "Upload requests must include an uploadType URL parameter and a URL path beginning with /upload/"
      }
     }**

【问题讨论】:

  • 对你的错误做点什么!查看documentation 了解有关恢复中断文件上传的更多信息。
  • 错误没有解决办法
  • 哦,我明白了,我以为你说你不能恢复上传。错误仍然表明您以错误的方式上传它(documentation)。
  • 这是我所知道的多部分的最佳示例。 developers.google.com/drive/v3/web/…
  • multipart 对我来说工作正常,但是当涉及到可恢复时,这个错误就会返回

标签: php google-cloud-storage google-api-php-client resume-upload


【解决方案1】:

您的上传网址不正确,因为每当您必须上传文件时,在云存储桶中,上传网址的路径非常重要。不仅在 Google Cloud 上,甚至在 Amazon S3 或任何其他云存储环境中。这些存储桶为您的文件上传位置创建标准路径,并通过 CDN 边缘使其可用。所以有必要设置上传路径。

要制作基于标准 HTML 的文件上传,请参阅此链接。 https://cloud.google.com/appengine/docs/standard/php/googlestorage/user_upload

https://cloud.google.com/appengine/docs/standard/php/googlestorage/

【讨论】:

  • 你没有明白我的意思。我没有使用自定义库,我正在使用它,因为这就是发生此错误的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-14
  • 1970-01-01
  • 2019-05-18
  • 1970-01-01
  • 2015-02-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多