What is solution for downloading arbitrarily large files to Cloud Storage using Google App Engine php55 or php7?

前端 未结 2 1990
无人共我
无人共我 2021-01-27 03:28

I have a google app engine php55 service that periodically checks a public website and downloads a file. This file is typically small (<1MB). My simple app is based on the fo

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-27 04:13

    I would recommend you to use a Compute Engine Instance, since GAE has the 32MB limit on the responses size. I found this post, where the user checks if there are new files available, and if there is some file, he upload directly to GCS.

    In order to do it, and as specified in the documentation, you should create an instance in GCE,and install and configure the client library for the language that you are going to use (as you mentioned in your post that you were using PHP, all the links will be refering this language, but keep in mind that you can choose also other language as C++, Java, Python...).

    You can find here an example in PHP about how to upload an object to GCS:

    function upload_object($bucketName, $objectName, $source)
    {
        $storage = new StorageClient();
        $file = fopen($source, 'r');
        $bucket = $storage->bucket($bucketName);
        $object = $bucket->upload($file, [
            'name' => $objectName
        ]);
        printf('Uploaded %s to gs://%s/%s' . PHP_EOL, basename($source), $bucketName, $objectName);
    }
    

    You can also find other samples in the Github repository from Google Cloud Platform.

    Hope this helps!

提交回复
热议问题