Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
김재형
2020-06-17 15:26:08 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d1575cc4ef0448ac9ce8ac0ff2d5979402699e55
d1575cc4
1 parent
549fdaac
Fix s3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
10 deletions
backend/api/views.py
secrets.json
backend/api/views.py
View file @
d1575cc
...
...
@@ -22,7 +22,7 @@ from django.conf import settings
import
jwt
from
django.http
import
HttpResponse
,
JsonResponse
from
khudrive.settings
import
AWS_SESSION_TOKEN
,
AWS_SECRET_ACCESS_KEY
,
AWS_ACCESS_KEY_ID
,
AWS_REGION
,
\
AWS_STORAGE_BUCKET_NAME
AWS_STORAGE_BUCKET_NAME
,
AWS_ENDPOINT_URL
class
UserViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -183,11 +183,15 @@ class ItemViewSet(viewsets.ViewSet):
# url: items/11/
# 마지막 slash도 써주어야함
def
get
(
self
,
request
,
pk
):
s3
=
boto3
.
client
(
's3'
,
aws_access_key_id
=
AWS_ACCESS_KEY_ID
,
aws_secret_access_key
=
AWS_SECRET_ACCESS_KEY
,
aws_session_token
=
AWS_SESSION_TOKEN
,
config
=
Config
(
signature_version
=
's3v4'
))
s3
=
boto3
.
client
(
's3'
,
region_name
=
AWS_REGION
,
aws_access_key_id
=
AWS_ACCESS_KEY_ID
,
aws_secret_access_key
=
AWS_SECRET_ACCESS_KEY
,
aws_session_token
=
AWS_SESSION_TOKEN
,
endpoint_url
=
AWS_ENDPOINT_URL
or
None
,
config
=
Config
(
s3
=
{
'addressing_style'
:
'path'
})
)
s3_bucket
=
AWS_STORAGE_BUCKET_NAME
item
=
Item
.
objects
.
filter
(
item_id
=
pk
)
...
...
@@ -329,7 +333,7 @@ class ItemViewSet(viewsets.ViewSet):
url_path
=
'children'
,
url_name
=
'children'
)
def
children
(
self
,
request
,
pk
):
if
request
.
method
==
'GET'
:
children
=
Item
.
objects
.
filter
(
parent
=
pk
,
is_deleted
=
False
)
children
=
Item
.
objects
.
filter
(
parent
=
pk
,
is_deleted
=
False
,
status
=
True
)
children_data
=
serializers
.
serialize
(
"json"
,
children
)
json_children
=
json
.
loads
(
children_data
)
parent
=
Item
.
objects
.
filter
(
item_id
=
pk
)
# item
...
...
@@ -380,7 +384,15 @@ class ItemViewSet(viewsets.ViewSet):
url_path
=
'upload'
,
url_name
=
'upload'
)
def
upload
(
self
,
request
,
pk
):
if
request
.
method
==
'POST'
:
s3
=
boto3
.
client
(
's3'
)
s3
=
boto3
.
client
(
's3'
,
region_name
=
AWS_REGION
,
aws_access_key_id
=
AWS_ACCESS_KEY_ID
,
aws_secret_access_key
=
AWS_SECRET_ACCESS_KEY
,
aws_session_token
=
AWS_SESSION_TOKEN
,
endpoint_url
=
AWS_ENDPOINT_URL
or
None
,
config
=
Config
(
s3
=
{
'addressing_style'
:
'path'
})
)
s3_bucket
=
AWS_STORAGE_BUCKET_NAME
# 파일 객체 생성
...
...
@@ -412,12 +424,19 @@ class ItemViewSet(viewsets.ViewSet):
3600
)
item
=
Item
.
objects
.
filter
(
item_id
=
upload_item
.
item_id
)
item_data
=
serializers
.
serialize
(
"json"
,
item
)
json_item
=
json
.
loads
(
item_data
)
res
=
json_item
[
0
][
'fields'
]
res
[
'id'
]
=
json_item
[
0
][
'pk'
]
data
=
{
"signed_url"
:
presigned_post
,
'url'
:
'https://
%
s.s3.amazonaws.com/
%
s'
%
(
s3_bucket
,
file_name
)
'url'
:
'
%
s/
%
s'
%
(
presigned_post
[
"url"
],
file_name
),
'item'
:
res
}
return
Response
(
{
'presigned_post'
:
presigned_post
,
'proc_data'
:
data
}
,
status
=
status
.
HTTP_200_OK
)
return
Response
(
data
,
status
=
status
.
HTTP_200_OK
)
# url: /status/
@action
(
methods
=
[
'POST'
],
detail
=
True
,
permission_classes
=
[
AllowAny
],
...
...
secrets.json
0 → 100644
View file @
d1575cc
{
"AWS_SESSION_TOKEN"
:
""
,
"AWS_SECRET_ACCESS_KEY"
:
"secret_key"
,
"AWS_ACCESS_KEY_ID"
:
"access_key"
,
"AWS_REGION"
:
"us-west-2"
,
"AWS_STORAGE_BUCKET_NAME"
:
"bucket"
,
"AWS_ENDPOINT_URL"
:
"http://localhost:39000"
}
\ No newline at end of file
Please
register
or
login
to post a comment