신은섭(Shin Eun Seop)

file download

......@@ -30,7 +30,7 @@ def list_path(bucket, user, path):
files.append({'type':'file', 'name':file})
return {'files':files}
def upload_file(bucket, user, local_path, key):
return S3.upload_file(local_path, bucket, user+"/"+key)
......
......@@ -57,7 +57,11 @@
<a href="{% url 'file_delete' path=new_path %}"><i class="trash alternate outline icon"></i></a>
{% endwith %}
</td>
<td class="center aligned collapsing"><i style="cursor: pointer;" class="download icon"></i></td>
<td class="center aligned collapsing">
{% with new_path=path|add:file.name %}
<a href="{% url 'file_download' path=new_path %}"><i style="cursor: pointer;" class="download icon"></i></a>
{% endwith %}
</td>
</tr>
{% endfor %}
</tbody>
......
......@@ -6,10 +6,12 @@ from restful.models import File
from django.views import View
from django.core.files.base import ContentFile
from django.middleware import csrf
from dcloud import settings
from django.http import HttpResponse
import os
import requests
def home(request):
return render(request, 'website/home.html')
......@@ -29,6 +31,7 @@ def file_upload(request, path):
cookies['csrftoken'] = csrf.get_token(request)
headers = {'X-CSRFToken': cookies['csrftoken']}
requests.post('http://localhost:8000/restapi/list/'+path, files={'file': file}, headers=headers, cookies=cookies)
# TODO delete mdeia/file
return redirect('file_list', path=path)
@login_required
......@@ -46,10 +49,31 @@ def file_delete(request, path):
cookies['csrftoken'] = csrf.get_token(request)
headers = {'X-CSRFToken': cookies['csrftoken']}
requests.delete('http://localhost:8000/restapi/file/'+path, headers=headers, cookies=cookies)
return redirect('file_list', path="/".join(path.split("/")[:-2]))
new_path = "/".join(path.split("/")[:-1])
if new_path != '':
new_path = new_path+'/'
return redirect('file_list', path=new_path)
@login_required
def file_download(request, path):
cookies = {'sessionid' : request.session.session_key}
requests.get('http://localhost:8000/restapi/file/'+path, cookies=cookies)
return redirect('file_list', path="/".join(path.split("/")[:-2]))
\ No newline at end of file
file_path = os.path.join(settings.MEDIA_ROOT, path)
if os.path.exists(file_path):
with open(file_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type='multipart/form-data' )
response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
return response
raise Http404
@login_required
def file_view(request, path):
cookies = {'sessionid' : request.session.session_key}
requests.get('http://localhost:8000/restapi/file/'+path, cookies=cookies)
file_path = os.path.join(settings.MEDIA_ROOT, path)
if os.path.exists(file_path):
with open(file_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type='text/plain' )
response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
return response
raise Http404
\ No newline at end of file
......