NickCourage's avatar

Can someone recommend some tutorials or resources for this?

Hi - I'm fairly new to Laravel and AWS but am trying to get started on user file uploads on to AWS S3. Of course I've looked about already but can't seem to find anything specific to individual users uploading documents/files to my AWS S3 bucket. For example, if I wanted a user to upload a word document, how could you do that from a Laravel app to a bucket in S3, make it private and associate to that user?

NB I know this is a broad question and would probably get down-voted on StackOverflow but all I'm asking for is a point in the right direction to some examples, tutorials, etc.

0 likes
3 replies
bugsysha's avatar

I haven't seen something like that, but I advise you to read the documentation and try. It is super simple.

martinbean's avatar
Level 80

@nickcourage S3 is just an object store. There’s no “associating” it with a user in your application. You read and write objects (file); nothing more.

If you want to associate an object with a user, then you’d store a reference to the object and your user in your own database.

Laravel’s filesystem component has S3 support out of the box. You just need to set the relevant values in your config/filesystems.php file and set the default driver from local to s3. You can then upload user-submitted files just like any other file:

<input type="file" name="resume" />
$path = $request->file('resume')->store('resumes');

This will return the path the object was stored in (i.e. resumes/somerandomhash.docx) which you can then save to your database along with the authenticated user’s ID:

$request->user()->resumes()->create([
    'path' => $path,
]);

Documentation:

NickCourage's avatar

@bugsysha @martinbean Thank you both for your replies - That's given me a better insight than before I asked! @martinbean that would explain why I've not been able to find much and it's obvious that I need spend some more time studying it. Thank you although I'm still unsure about how you would make these private but then accessible to particular users...

Please or to participate in this conversation.