Ubuntu

사용자별 버킷 생성

......@@ -59,6 +59,7 @@ def logout(request):
def register(request):
Cog = cognito.Cognito()
reg=views.FileView()
if request.user.is_authenticated: raise PermissionDenied
if request.method == "POST":
require_keys = ('username', 'password', 'first_name', 'last_name', 'email')
......@@ -97,7 +98,7 @@ def register(request):
},
])
Cog.confirm_sign_up(username=request.POST['username']);
print(views.create_bucket)
print(reg.create_bucket(request))
return redirect('/main')
else:
return render(request, 'register.html', {
......
......@@ -25,10 +25,6 @@ config.read('config.ini')
# file.name
# )
# file_urls = [f"https://s3.us-ease-1.amazonaws.com/khuloud/{file.name}" for file in request.FILES.getlist('file')]
# return JsonResponse({'files':file_urls}, status=200)
class FileView(View):
#keys=aws_key()
s3_client = boto3.client(
......@@ -36,8 +32,6 @@ class FileView(View):
aws_access_key_id = config['aws']['AWS_ACCESS_KEY_ID'],
aws_secret_access_key=config['aws']['AWS_SECRET_ACCESS_KEY']
)
@csrf_exempt
def post(self, request):
# filename = request.data.get('filename')
......@@ -46,9 +40,17 @@ class FileView(View):
self.s3_client.upload_file(filepath, bucket_name, filepath)
s3link='https://s3.console.aws.amazon.com/s3/buckets/'+bucket_name+'/'+filepath
return JsonResponse({'file':s3link})
@csrf_exempt
def create_bucket(request):
s3 = boto3.client('s3')
s3.create_bucket(Bucket='request.user.username')
return Bucket
@csrf_exempt
def create_bucket(self,request):
"""
s3 = boto3.resource('s3',
aws_access_key_id = config['aws']['AWS_ACCESS_KEY_ID'],
aws_secret_access_key=config['aws']['AWS_SECRET_ACCESS_KEY']
)
"""
bucket=self.s3_client.create_bucket(
ACL='public-read-write',
Bucket=request.POST['username'],
CreateBucketConfiguration={
'LocationConstraint':'ap-northeast-2'},
)
......