Playing
01. DigitalOcean spaces with Laravel

Episodes

0%
Your progress
  • Total: 4m
  • Played: 0m
  • Remaining: 4m
Join or sign in to track your progress

Transcript

00:00
If you're thinking about using DigitalOcean Spaces within Laravel, this is actually incredibly easy to do, the main reason being that Spaces uses the same API as Amazon S3. So you can just go ahead and use the FlySystem S3 driver to get this up and running very,
00:18
very quickly. And that's what we're going to look at in this snippet. Okay. So first of all, let's come over to DigitalOcean and create a new space out here.
00:27
And let's go ahead and give this a name. So let's just say test for now and say test code course. That's obviously taken. Let's go ahead and choose a region, doesn't really matter in this case, let's choose Amsterdam.
00:37
And let's restrict file listing. This will mean that your items are private and we can only access them using our keys. So let's create this space and wait for this to finish and then we'll look at setting this up inside of Laravel.
00:50
Okay. So if we head over to a fresh Laravel project and open up config file systems, we already a default S3 item in here that we can use. And this uses the S3 driver.
01:01
So what I typically do is I create a different file system for every bucket that I have, whether that's on different service provider or using DigitalOcean. So I would call this something like test or videos, you know, depending on the bucket. Now we're going to leave the driver as S3.
01:19
We need to change, of course, the key and the secret and we need to change the region as well. And we also need to go ahead and add in another option in here to get this working with DigitalOcean. So the first thing is let's go and just switch this over to DO spaces key and DO spaces secret.
01:39
And I'm going to go ahead and pop the region in the bucket in here and not add them to EMB files because we don't really need to do that. They don't really secure. So for the region, we've chosen Amsterdam and that's Amsterdam 3.
01:51
So we just say AMS 3 and you'll find a list of these somewhere over on DigitalOcean, but you can pretty much just guess them. So if it's New York, for example, it's going to be NYC. Now for the bucket name, this is, of course, just going to be the name of your bucket and
02:05
we call that test code course. So just go ahead and pop that in there. And the other thing that you're going to need in here, you don't actually need the URL, you're just going to need the endpoint.
02:14
And this will be the endpoint to the specific region that you've chosen. So this follows the same pattern. It's just the region that you've chosen and then DigitalOceanSpaces.com. So all we need to do now is generate a key and a secret and we should be good to go.
02:30
So let's come over to EMB and come down and pop these inside of here. Let's grab both of these and we'll look at generating out a key over here. So we come over to our API section, we come down to our space access keys and generate a new key.
02:46
Let's just call this test again. So we'll go ahead and click the tick there, wait for that to finish and we get our test and our secret that we can just really conveniently copy over. And you won't see the secret ever again so make sure you do note that down before you
03:00
go ahead and navigate away from this page. So now that we've got these two items in here, what we should be able to do is over on web use the storage facade to go ahead and choose the disk which we've now called test and we can go ahead and put a file in here.
03:14
So let's say test.txt and let's just write some content to it, it doesn't really matter in this case. So let's come over to the browser and just open up fresh.local and of course because this is a fresh installation, I'm going to need to go ahead and do a composer require
03:31
on the fly system AWS package so let's wait for this to finish. Alrighty so now that's done, let's go ahead and give that a refresh and come back over to the space that we had created earlier and sure enough we have that file in there. And let's just go ahead and download this and there we go.
03:54
Sure enough that has worked. So you can now use this like you would normally do with an Amazon S3 bucket, you can grab items out there, you know upload files, put contents into here or of course just replace this out with a file location to upload a file.
1 episode 4 mins

Overview

Here's how to use DigitalOcean spaces with Laravel's Filesystem. It's as easy as using S3!

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!