허진호

Merge branch 'dev' of https://github.com/jh8579/fileshell_cloudcomputing into dev

# Conflicts:
#	fileshell/models.py
#	fileshell/settings.py
#	fileshell/urls.py
#	fileshell/views.py
#	templates/base.html
...@@ -27,6 +27,7 @@ ALLOWED_HOSTS = [ ...@@ -27,6 +27,7 @@ ALLOWED_HOSTS = [
27 '13.125.219.232', 27 '13.125.219.232',
28 'localhost', 28 'localhost',
29 '.ap-northeast-2.compute.amazonaws.com', 29 '.ap-northeast-2.compute.amazonaws.com',
30 + '127.0.0.1',
30 ] 31 ]
31 32
32 33
...@@ -138,5 +139,5 @@ SECRET_KEY = secret_key ...@@ -138,5 +139,5 @@ SECRET_KEY = secret_key
138 139
139 #AWS Access 140 #AWS Access
140 AWS_ACCESS_KEY_ID = key_id 141 AWS_ACCESS_KEY_ID = key_id
141 -AWS_SECRET_ACCESS_KEY =secret_access_key 142 +AWS_SECRET_ACCESS_KEY = secret_access_key
142 AWS_STORAGE_BUCKET_NAME ='fileshell-test' 143 AWS_STORAGE_BUCKET_NAME ='fileshell-test'
......
...@@ -3,6 +3,8 @@ from storages.backends.s3boto3 import S3Boto3Storage ...@@ -3,6 +3,8 @@ from storages.backends.s3boto3 import S3Boto3Storage
3 from .settings import AWS_STORAGE_BUCKET_NAME, LOCAL_DOWNLOAD_PATH 3 from .settings import AWS_STORAGE_BUCKET_NAME, LOCAL_DOWNLOAD_PATH
4 import boto3 4 import boto3
5 import os 5 import os
6 +import boto3.session
7 +
6 8
7 class MediaStorage(S3Boto3Storage): 9 class MediaStorage(S3Boto3Storage):
8 location = settings.MEDIAFILES_LOCATION 10 location = settings.MEDIAFILES_LOCATION
...@@ -24,10 +26,23 @@ class MediaStorage(S3Boto3Storage): ...@@ -24,10 +26,23 @@ class MediaStorage(S3Boto3Storage):
24 client.upload_fileobj(nf, AWS_STORAGE_BUCKET_NAME, user.username + '/' + dir + file.name) 26 client.upload_fileobj(nf, AWS_STORAGE_BUCKET_NAME, user.username + '/' + dir + file.name)
25 os.remove('tempfile') 27 os.remove('tempfile')
26 # putResponse = client.put_object(Bucket=AWS_STORAGE_BUCKET_NAME, Key= file_name) 28 # putResponse = client.put_object(Bucket=AWS_STORAGE_BUCKET_NAME, Key= file_name)
27 - 29 + """
28 def download_file(file_name, dir): 30 def download_file(file_name, dir):
29 client = boto3.resource('s3') 31 client = boto3.resource('s3')
30 client.Bucket(AWS_STORAGE_BUCKET_NAME).download_file(Key= dir, Filename=LOCAL_DOWNLOAD_PATH+file_name) 32 client.Bucket(AWS_STORAGE_BUCKET_NAME).download_file(Key= dir, Filename=LOCAL_DOWNLOAD_PATH+file_name)
33 + """
34 +
35 + def down(filename, bucketPath):
36 + session = boto3.session.Session(region_name='us-west-2')
37 + s3 = session.client('s3')
38 + filepath = settings.LOCAL_DOWNLOAD_PATH + filename
39 + response_headers = {
40 + 'response-content-type': 'application/force-download',
41 + 'response-content-disposition': 'attachment;filename="%s"' % filename
42 + }
43 + url = s3.generate_presigned_url('get_object', Params={'Bucket': 'fileshell-test', 'Key': bucketPath},
44 + ExpiresIn=100)
45 + return url
31 46
32 def delete_file(file_name, dir): 47 def delete_file(file_name, dir):
33 client = boto3.resource('s3') 48 client = boto3.resource('s3')
......
...@@ -173,11 +173,14 @@ def download(request, bucketPath, filename, dir): ...@@ -173,11 +173,14 @@ def download(request, bucketPath, filename, dir):
173 173
174 # 필터링 된 파일 최근 열람 시간 갱신 174 # 필터링 된 파일 최근 열람 시간 갱신
175 File.objects.filter(title=filename, bucketPath=dir).update(last_view_TM=datetime.datetime.now()) 175 File.objects.filter(title=filename, bucketPath=dir).update(last_view_TM=datetime.datetime.now())
176 - 176 + """
177 # s3에서 해당 파일을 정해진 경로로 다운로드 177 # s3에서 해당 파일을 정해진 경로로 다운로드
178 MediaStorage.download_file(filename, bucketPath) 178 MediaStorage.download_file(filename, bucketPath)
179 + """
179 180
180 - return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/')) 181 + url = MediaStorage.down(filename, bucketPath)
182 +
183 + return HttpResponseRedirect(url)
181 184
182 def delete(request, bucketPath, filename, dir): 185 def delete(request, bucketPath, filename, dir):
183 186
......
1 {% extends 'base.html'%} 1 {% extends 'base.html'%}
2 {% load staticfiles %} 2 {% load staticfiles %}
3 {% block content %} 3 {% block content %}
4 - <div>
5 - <div class="right_bar">
6 - <li class="nav-item1"><a href="" class="nav-link-right"> <img class = 'add_folder_icon' src= "{% static 'resources/upload.png' %}" width="30" height="30"/> 파일 업로드</a></li>
7 - <form action={% url 'upload' %} method="post" enctype="multipart/form-data" novalidate>
8 - {% csrf_token %}
9 -
10 - <input type ="file" name = "source-file">
11 - <input type = "submit">
12 - </form>
13 - <li class="nav-item1"><a href="" class="nav-link-right"> <img class = 'add_folder_icon' src= "{% static 'resources/add_folder.png' %}" width="30" height="30"/> 새 폴더</a></li>
14 - <form action="{% url 'add_folder' %}" method="post" enctype="multipart/form-data">{% csrf_token %}
15 - <input type="dir_name" name="dir_name" id="dir_name" required="required" placeholder="New Folder Name">
16 - <input type = "submit">
17 - </form>
18 - </div>
19 - </div>
20 <div class="frame"> 4 <div class="frame">
21 <!-- //header --> 5 <!-- //header -->
22 <div class="container"> 6 <div class="container">
......