如何将图像上传到Firebase云存储?该文档仅提供了这些方法,而没有提供上载方法。这是文档链接https://firebase-php.readthedocs.io/en/stable/cloud-storage.html
$storage = $factory->createStorage();
$storageClient = $storage->getStorageClient();
$defaultBucket = $storage->getBucket();
我看到了另一个与堆栈有关的问题,但不明白答案。 我还想获得一个到存储文件的链接。
提前谢谢!
答案 0 :(得分:1)
您可以这样做,
$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);
gcp github存储库上有示例。
答案 1 :(得分:1)
检查官方的火力基地documentation,如此处所述:
“ 要将文件上传到Cloud Storage,您首先创建对文件完整路径(包括文件名)的引用。”
例如:
// Create a root reference
var storageRef = firebase.storage().ref();
// Create a reference to 'mountains.jpg'
var mountainsRef = storageRef.child('mountains.jpg');
// Create a reference to 'images/mountains.jpg'
var mountainImagesRef = storageRef.child('images/mountains.jpg');
// While the file names are the same, the references point to different files
mountainsRef.name === mountainImagesRef.name // true
mountainsRef.fullPath === mountainImagesRef.fullPath // false
此外,我发现了另一个线程here,您可以在其中找到使用php的示例