使用Google App Engine php55或php7将任意大文件下载到Cloud Storage的解决方案是什么? [英] What is solution for downloading arbitrarily large files to Cloud Storage using Google App Engine php55 or php7?

本文介绍了使用Google App Engine php55或php7将任意大文件下载到Cloud Storage的解决方案是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google App引擎php55服务,该服务会定期检查公共网站并下载文件.该文件通常很小(< 1MB).我的简单应用程序基于以下内容:

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 following:

<?php
$strSource = 'https://example.com/file.zip';

$strBucket = 'bucket-1234';
$strDirectory = '/path/to/file/'; // Google Cloud Storage directory
$strName = 'file.zip';
$strDestination = 'gs://' . $strBucket . '.appspot.com' . $strDirectory . $strName;

copy($strSource,$strDestination);
?>

我发现此文件有时更大(超过 32MB响应大小限制).如何编写此脚本来处理文件大小为1MB或100MB?

I found this file occasionally is larger (over the 32MB response size limit). How do I write this script to handle the file whether it is 1MB or 100MB?

我看到人们推荐" Blobstore ",这是我没有经验的.即使我了解该解决方案(该解决方案似乎专注于另一种用途) ),它似乎根本不适用于PHP.我想念什么吗?

I see people recommend "Blobstore," which is something I do not have experience with. Even if I understood that solution (which seems to be focused on a very different use case), it does not appear to be available for PHP at all. Am I missing something?

推荐答案

我建议您使用Compute Engine实例,因为GAE的响应大小限制为32MB. 我发现了这篇文章,用户在其中检查是否有新文件可用,如果有新文件,他直接上传到GCS.

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.

为了做到这一点,并按照文档,则应在GCE中创建一个实例,并安装并为您要使用的语言配置客户端库(正如您在帖子中提到的那样,您使用的是PHP,所有链接都将引用该语言,但是请记住,您也可以选择其他语言语言,例如C ++,Java,Python ...).

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...).

您可以在PHP中找到有关如何将对象上传到GCS的示例:

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

您还可以在 Github存储库中找到其他示例来自Google Cloud Platform.

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

希望这会有所帮助!

这篇关于使用Google App Engine php55或php7将任意大文件下载到Cloud Storage的解决方案是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆