Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+10 votes
376 views
in Plugins by
edited by
Hi

There is a few questions about upload to AWS S3, But I can't find a solid solution.

I want to upload to s3, is there any plugin, for that?

P.S: I found a repo for aws, it's may help.

https://github.com/aws/aws-sdk-php
Q2A version: 1.8.6
by
+2
I don't think such a plugin exists.
Also, related: https://www.question2answer.org/qa/83151#a83643
by
I am ok with some reductions in performance (if any), For the sake of keeping my production VPS light by serving and storage only code base and DB,  And ready for CPU and RAM related jobs and keep S3 for Storage of users assets.

1 Answer

0 votes
by

To save uploaded files to AWS S3, you can follow these general steps:

  1. Create an S3 bucket: Log in to your AWS account and create a new S3 bucket, or use an existing one. Make sure to take note of the bucket name and the AWS region in which it is located.
  2. Set up AWS credentials: Generate AWS access key and secret access key. This will be used to authenticate your application or code when interacting with the S3 bucket. Store these keys securely as they grant access to your AWS account.
  3. Install an AWS SDK or library: Depending on the programming language you're using, you can install the AWS SDK or library to enable interaction with the S3 bucket. This will provide you with methods and functions for uploading files to S3.
  4. Write code to upload files: In your application or code, write code to upload the files to S3 using the AWS SDK or library. You will typically need to specify the bucket name, the path or key under which the file will be saved, and the file contents itself.

Here is an example code snippet for uploading a file to S3 using the AWS SDK for Python (boto3):

import boto3

s3 = boto3.resource('s3', aws_access_key_id='YOUR_ACCESS_KEY', aws_secret_access_key='YOUR_SECRET_KEY')

bucket_name = 'your-bucket-name'

key = 'path/to/file.txt'

file_path = '/path/to/local/file.txt'


s3.Bucket(bucket_name).upload_file(file_path, key)
Replace YOUR_ACCESS_KEY and YOUR_SECRET_KEY with your AWS access key and secret access key, respectively. Replace your-bucket-name with the name of your S3 bucket, and path/to/file.txt with the path or key under which you want to save the file in the bucket. Finally, replace /path/to/local/file.txt with the path to the local file you want to upload.
...