austintoddj / canvas

Publishing on your own terms
http://trycanvas.app
MIT License
3.23k stars 517 forks source link

GCP Cloud Storage Bucket with Laravel Spatie #1374

Closed ABC2015 closed 7 months ago

ABC2015 commented 8 months ago

Discussed in https://github.com/austintoddj/canvas/discussions/1373

Originally posted by **ABC2015** November 1, 2023 Hi Community: Wanted to confirm that use the GCP storage bucket using Laravel Spatie for GCP cloud storage works as expected. Having some trouble getting images to POST based on the network request we are seeing. //Config below** 'storage_disk' => env('CANVAS_STORAGE_DISK', 'gcs'), 'storage_path' => env('CANVAS_STORAGE_PATH', 'public/canvas'), 'upload_filesize' => env('CANVAS_UPLOAD_FILESIZE', 1048576), **//General Storage Bucket** 'gcs' => [ 'driver' => 'gcs', 'key_file_path' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json 'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'), // optional: is included in key file 'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'), 'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', ""), // optional: /default/path/to/apply/in/bucket 'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below 'visibility' => 'private', // optional: public|private 'metadata' => ['cacheControl' => 'public,max-age=86400'], // optional: default metadata ], ISSUE: Essentially the application post request to google cloud apis does not seem to be placing the file in the right path. ![upload image](https://github.com/austintoddj/canvas/assets/6826984/d48e89ae-9ec2-4f7a-aeeb-092ef32fa894) ![upload image2](https://github.com/austintoddj/canvas/assets/6826984/69088444-633f-4f99-9501-070952d70e30) Video of Issue https://app.screencast.com/dFyxElAfDPBvB https://app.screencast.com/a1GGu1I3FpL2j Any suggestions would be helpful.
ABC2015 commented 8 months ago

Hi @austintoddj - hope the week is progressing well - Just wanted to confirm whether it's the intention to have gcp spatie OOTB (https://github.com/spatie/laravel-google-cloud-storage) integrated - unless we missed something in the docs) - or should we do the wiring ourselves? We have done this in our other Laravel applications - just wanted to get confirmation one way or the other - thanks in advance.

austintoddj commented 8 months ago

Hi @ABC2015. I haven't tried integrating that package and Canvas. It seems like it should work out of the box, given that it's a pretty generic storage driver.

The URL being returned is that path to the uploaded file, as seen in the upload method here:

public function store()
{
    $payload = request()->file();

    if (! $payload) {
        return response()->json(null, 400);
    }

    // Only grab the first element because single file uploads
    // are not supported at this time
    $file = reset($payload);

    $path = $file->store(Canvas::baseStoragePath(), [
        'disk' => config('canvas.storage_disk'),
    ]);

    return Storage::disk(config('canvas.storage_disk'))->url($path);
}

What's the payload of the first screenshot (POST request to /api/uploads) above?

ABC2015 commented 8 months ago

Hi @austintoddj https://app.screencast.com/Ft01eBio64W1j (Parsed) Sourced Payload (Sourced Payload)

ABC2015 commented 8 months ago

@austintoddj uploaded the payload - in this case - the path for the uploads vs what's the actual gcp storage does not match from our test - which results in the image not being found.

ABC2015 commented 7 months ago

@austintoddj we ended implementing it in a different manner. So we'll close this out.

austintoddj commented 7 months ago

@ABC2015 Thanks for closing the loop here. Apologies, personal life is a bit nuts right now and I wasn't able to dig into this like I intended.

Feel free to open another issue if something comes up.

ABC2015 commented 7 months ago

No worries - all good.