如何通过laravel中的代码将文件扩展名也发送到gcloud应用程序存储桶?
我通过在laravel中编码将我的图片存储在gcloud应用程序存储桶中,它正在工作 但是我想用和我在DB中保存的相同的名称保存它们,并使用它们的扩展名,这样我就可以很容易地检索它们 图像保存在GCS存储桶中,名称由他们自动创建,不带扩展名 这是我的密码:如何通过laravel中的代码将文件扩展名也发送到gcloud应用程序存储桶?,laravel,google-app-engine,google-cloud-platform,google-cloud-storage,gcloud,Laravel,Google App Engine,Google Cloud Platform,Google Cloud Storage,Gcloud,我通过在laravel中编码将我的图片存储在gcloud应用程序存储桶中,它正在工作 但是我想用和我在DB中保存的相同的名称保存它们,并使用它们的扩展名,这样我就可以很容易地检索它们 图像保存在GCS存储桶中,名称由他们自动创建,不带扩展名 这是我的密码: public function store(Request $request) { if ($request->hasFile('image')) { $imageName = time().'.'.$req
public function store(Request $request)
{
if ($request->hasFile('image')) {
$imageName = time().'.'.$request->image->extension();
$photo = $request->image->storeAs('ufurnitures-img', $imageName, 'public');
}
// Save the data into GCS
$extension = $request->image->getClientOriginalExtension();
$storage = new StorageClient([
'projectId' => 'ufurnitures'
]);
$bucket = $storage->bucket('ufurnitures-img');
$bucket->upload(
//fopen($request->image.'.'.$extension, 'r') //This one is not working
fopen($request->image, 'r') //This one is working
);
// Save the data into database
Product::create([
'name' => $request->name,
'price' => $request->price,
'description' => $request->description,
'image' => $photo
]);
$request->session()->flash('msg','Your product has been added');
return redirect()->back();
}
您可以指定
您可以指定
您可以将答案标记为有效,以允许其他用户信任它!我的错!我以为是我干的P现在完成:)再次感谢^ ^您可以将答案标记为有效,以允许其他用户信任它!我的错!我以为是我干的P现在完成:)再次感谢^_^
$options = [
'name' => '/path/to/file.extension',
];
$bucket->upload(
//fopen($request->image.'.'.$extension, 'r') //This one is not working
fopen($request->image, 'r'), //This one is working
$options
);