Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带有下载文件名的Google应用程序引擎getImageServingUrl_Php_Google App Engine_Google Cloud Storage - Fatal编程技术网

Php 带有下载文件名的Google应用程序引擎getImageServingUrl

Php 带有下载文件名的Google应用程序引擎getImageServingUrl,php,google-app-engine,google-cloud-storage,Php,Google App Engine,Google Cloud Storage,我正在使用这个方法生成一个图像的URL,它和下面列出的选项一起工作得很好 我可以添加“d”选项来强制下载文件,而不只是在浏览器中显示。问题是文件名默认为“unnamed.[ext]”(其中[ext]是源文件扩展名)。是否有办法将原始文件名传递到请求的某个位置 我可以使用CloudStorageTools::serve以给定的名称保存文件,但例如,我不能使用图像大小调整功能 我不知道有任何选项允许这样做。 但我有另一个想法,这有点复杂,但对你来说可能是个不错的选择。 您可以使用nginx构建一个反

我正在使用这个方法生成一个图像的URL,它和下面列出的选项一起工作得很好

我可以添加“d”选项来强制下载文件,而不只是在浏览器中显示。问题是文件名默认为“unnamed.[ext]”(其中[ext]是源文件扩展名)。是否有办法将原始文件名传递到请求的某个位置


我可以使用CloudStorageTools::serve以给定的名称保存文件,但例如,我不能使用图像大小调整功能

我不知道有任何选项允许这样做。 但我有另一个想法,这有点复杂,但对你来说可能是个不错的选择。 您可以使用nginx构建一个反向代理,它将通过您自己的域为您提供谷歌图像。然后可以将原始请求中的文件名作为参数发送。在nginx中,您可以在代理请求之前从请求中删除filename参数,并将其添加为头以在响应中定义文件名。 在nginx配置中,这是一个非常严格的过程:

location /image-storage/ {
    expires 30d;

    #Get rid of headers to be overwritten
    proxy_hide_header Pragma;
    proxy_hide_header Cache-Control;
    proxy_hide_header Content-Disposition;

    #Add caching headers
    add_header Pragma public;
    add_header Cache-Control "public";
    #If the parameter "filename" is sent, use it as filename
    if ($arg_filename) {
        add_header Content-Disposition 'inline; filename="$arg_filename"';
    }
    #If the parameter "dl_filename" is sent, use it as filename and init download (attachment)
    if ($arg_dl_filename) {
        add_header Content-Disposition 'attachment; filename="$arg_dl_filename"';
    }

    #Proxy the request to google
    proxy_pass       https://lh3.googleusercontent.com/;
    proxy_set_header Host lh3.googleusercontent.com;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_buffering off;
}
这样,像:这样的url将被代理,响应将获得缓存和文件名的新标题