Superbalist / laravel-google-cloud-storage

A Google Cloud Storage filesystem for Laravel
MIT License
508 stars 145 forks source link

Move a file that exists locally to google cloud #110

Closed aghwotu closed 3 years ago

aghwotu commented 3 years ago

Hello there. Thank you for this package. I want to upload a pdf file I already stored locally to Google Cloud Storage. Please how do I do this? Thank you for your time.

$data = [
    'title' => 'This is my title',
    'date' => date('m/d/Y')
];
$filename = "JohnDoe";
$filename .= ".pdf";
$pdf = PDF::loadView('myPDF', $data); 
$fileStoragePath = '/path/to/pdf/' . $filename;
$path = public_path($fileStoragePath);
$pdf->save($path);

$disk = Storage::disk('gcs');
// create a file - store pdf in the cloud
$disk->put('pdf/1.txt', 'Contents of sample text file');
idealerror commented 3 years ago

I believe you already had the answer at the end of your code.

$disk = Storage::disk('gcs');
// create a file - store pdf in the cloud
$disk->put('your.pdf', file_get_contents($path));
aghwotu commented 3 years ago

Hello, 👋 there. Thank you for your kind response. I have long since deployed this project and forgot to close the issue. I also wrote a tutorial about it here

Thank you again.

idealerror commented 3 years ago

Great writeup! :)