使用PHP createUploadUrl和选项Content = type image / jpeg将图像上传到Google Cloud 端存储时,我会收到错误信息
"Invalid options supplied: Content-Type..."
这是代码:
$options = [ 'gs_bucket_name' => 'mybucket', 'Content-Type' => 'image/jpeg' ];
$upload_url = CloudStorageTools::createUploadUrl('/upload.php', $options);
图像已上载,但显示为二进制/八位字节流文件(默认为GCS) . 我也尝试了mimeType和image / jpg . 我究竟做错了什么?
2 回答
将Content-Type作为上下文的一部分传递给move_uploaded_file(),而不是createUploadURL选项的一部分 .
上传文件后,请不要像大多数文档一样使用 move_uploaded_file() ,因为它是 looses the type information during the move .
更糟糕的是,如果您尝试在移动之前设置它并将类型设置为默认值,则忽略 stream_context_create() - binary/octet-stream .
只需使用 rename() 而不是 move_uploaded_file() . 括号中的参数是相同的 .
如果有帮助,这就是我的榜样 .
简单的一个:
这是一个更复杂的强制类型(如果你想):