Resumable upload using Google Client API . Invalid Upload URL

痴心易碎 提交于 2019-12-10 12:25:56

问题


I am unable to perform resumable upload using this api please Help Me.This Code Working Fine Until i used resumable Upload . I can Upload FIle Using Multipart but not able upload big files with multipart

MY Code

            $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);

Response Error

      {
      "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/"
      }
     }**

回答1:


Your upload url is not correct, because whenever you have to upload your files, in cloud buckets the path for Upload URL is very important. Not only on Google Cloud but even in Amazon S3 or any other cloud storage environments. These buckets create standard path for your file upload location, and make it available via CDN edges. SO it is necessary to set upload path.

For making standard HTML based file upload refer this link. https://cloud.google.com/appengine/docs/standard/php/googlestorage/user_upload

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



来源:https://stackoverflow.com/questions/43062584/resumable-upload-using-google-client-api-invalid-upload-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!