无法创建要条带化的文件.Get-error仅支持普通文件资源流



我试图创建存储在AmazonS3中的图像到Stripe,但在创建文件时遇到了问题。这是我用来创建Stripe 文件的代码

use StripeFile;
...
$fp = fopen($filePath, 'r');
return File::create([
'file' => $fp,
'purpose' => 'identity_document'
], $this->stripeOptions());

当我尝试将图像创建到Stripe时引发错误。

StripeExceptionInvalidArgumentException: Only plainfile resource streams are supported in C:xampphtdocsABCDvendorstripestripe-phplibApiRequestor.php:407

错误表明,Stripe只支持plainfile resource streams,当我尝试fopen()dd()结果时,它返回一个stream resource对象。

stream resource @1003 ▼
crypto: array:4 [▼
"protocol" => "TLSv1.2"
"cipher_name" => "ECDHE-RSA-AES128-GCM-SHA256"
"cipher_bits" => 128
"cipher_version" => "TLSv1.2"
]
timed_out: false
blocked: true
eof: false
wrapper_data: array:11 [▼
0 => "HTTP/1.1 200 OK"
1 => "x-amz-id-2: zp14jBOfTbvgv27M4EZXZDhYgmwhHgsADCpcKwSCh0y4s0eMKfeC7DMjXBEzClrGUC+lbZ7RGFU="
2 => "x-amz-request-id: 8W1S1K0Q2J5W9ZBM"
3 => "Date: Tue, 13 Oct 2020 06:11:42 GMT"
4 => "Last-Modified: Tue, 13 Oct 2020 06:11:34 GMT"
5 => "ETag: "263820eaa58f3a5ddc2dc504732839ca""
6 => "Accept-Ranges: bytes"
7 => "Content-Type: image/jpeg"
8 => "Content-Length: 187383"
9 => "Server: AmazonS3"
10 => "Connection: close"
]
wrapper_type: "http"
stream_type: "tcp_socket/ssl"
mode: "r"
unread_bytes: 0
seekable: false
uri: "https://vetvideo.s3.amazonaws.com/admin/verification/1602569479_product2.jpg"
options: []
}

我试着搜索plain object,得到了几个这样的问题,但还没有解决。有人能帮忙吗?

如果文件源在vetvideo.s3上,则不能直接通过URL上传。您必须将文件本身下载到服务器,然后使用PHP中的file对象将其上传到Stripe,就像这样,使用PHP中新的面向服务的调用[1]。

$fp = fopen('/path/to/a/local/file.jpg', 'r');
$stripe->files->create([
'purpose' => 'identity_document',
'file' => $fp
]);

[1]https://github.com/stripe/stripe-php/wiki/Migration-to-StripeClient-and-services-in-7.33.0#client-和服务

相关内容

最新更新