허진호

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 = [
'13.125.219.232',
'localhost',
'.ap-northeast-2.compute.amazonaws.com',
'127.0.0.1',
]
......@@ -138,5 +139,5 @@ SECRET_KEY = secret_key
#AWS Access
AWS_ACCESS_KEY_ID = key_id
AWS_SECRET_ACCESS_KEY =secret_access_key
AWS_SECRET_ACCESS_KEY = secret_access_key
AWS_STORAGE_BUCKET_NAME ='fileshell-test'
......
......@@ -3,6 +3,8 @@ from storages.backends.s3boto3 import S3Boto3Storage
from .settings import AWS_STORAGE_BUCKET_NAME, LOCAL_DOWNLOAD_PATH
import boto3
import os
import boto3.session
class MediaStorage(S3Boto3Storage):
location = settings.MEDIAFILES_LOCATION
......@@ -24,10 +26,23 @@ class MediaStorage(S3Boto3Storage):
client.upload_fileobj(nf, AWS_STORAGE_BUCKET_NAME, user.username + '/' + dir + file.name)
os.remove('tempfile')
# putResponse = client.put_object(Bucket=AWS_STORAGE_BUCKET_NAME, Key= file_name)
"""
def download_file(file_name, dir):
client = boto3.resource('s3')
client.Bucket(AWS_STORAGE_BUCKET_NAME).download_file(Key= dir, Filename=LOCAL_DOWNLOAD_PATH+file_name)
"""
def down(filename, bucketPath):
session = boto3.session.Session(region_name='us-west-2')
s3 = session.client('s3')
filepath = settings.LOCAL_DOWNLOAD_PATH + filename
response_headers = {
'response-content-type': 'application/force-download',
'response-content-disposition': 'attachment;filename="%s"' % filename
}
url = s3.generate_presigned_url('get_object', Params={'Bucket': 'fileshell-test', 'Key': bucketPath},
ExpiresIn=100)
return url
def delete_file(file_name, dir):
client = boto3.resource('s3')
......
......@@ -173,11 +173,14 @@ def download(request, bucketPath, filename, dir):
# 필터링 된 파일 최근 열람 시간 갱신
File.objects.filter(title=filename, bucketPath=dir).update(last_view_TM=datetime.datetime.now())
"""
# s3에서 해당 파일을 정해진 경로로 다운로드
MediaStorage.download_file(filename, bucketPath)
"""
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
url = MediaStorage.down(filename, bucketPath)
return HttpResponseRedirect(url)
def delete(request, bucketPath, filename, dir):
......
{% extends 'base.html'%}
{% load staticfiles %}
{% block content %}
<div>
<div class="right_bar">
<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>
<form action={% url 'upload' %} method="post" enctype="multipart/form-data" novalidate>
{% csrf_token %}
<input type ="file" name = "source-file">
<input type = "submit">
</form>
<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>
<form action="{% url 'add_folder' %}" method="post" enctype="multipart/form-data">{% csrf_token %}
<input type="dir_name" name="dir_name" id="dir_name" required="required" placeholder="New Folder Name">
<input type = "submit">
</form>
</div>
</div>
<div class="frame">
<!-- //header -->
<div class="container">
......