Showing
1 changed file
with
5 additions
and
1 deletions
| ... | @@ -5,7 +5,7 @@ from rest_framework.response import Response | ... | @@ -5,7 +5,7 @@ from rest_framework.response import Response |
| 5 | from rest_framework import status | 5 | from rest_framework import status |
| 6 | from rest_framework.authentication import SessionAuthentication, BasicAuthentication | 6 | from rest_framework.authentication import SessionAuthentication, BasicAuthentication |
| 7 | from rest_framework.permissions import IsAuthenticated | 7 | from rest_framework.permissions import IsAuthenticated |
| 8 | - | 8 | +import os |
| 9 | from restful import s3_interface | 9 | from restful import s3_interface |
| 10 | 10 | ||
| 11 | from restful.models import File | 11 | from restful.models import File |
| ... | @@ -39,6 +39,8 @@ class FileList(APIView): | ... | @@ -39,6 +39,8 @@ class FileList(APIView): |
| 39 | file_path = '.' + file_serializer.data.get('file') | 39 | file_path = '.' + file_serializer.data.get('file') |
| 40 | user = request.user | 40 | user = request.user |
| 41 | data = s3_interface.upload_file(s3_interface.BUCKET, user.username, file_path, path+file_path.split('/')[-1]) | 41 | data = s3_interface.upload_file(s3_interface.BUCKET, user.username, file_path, path+file_path.split('/')[-1]) |
| 42 | + if os.path.exists(file_path): | ||
| 43 | + os.remove(file_path) | ||
| 42 | # TODO upload check | 44 | # TODO upload check |
| 43 | # TODO remove local file | 45 | # TODO remove local file |
| 44 | return Response(file_serializer.data, status=status.HTTP_201_CREATED) | 46 | return Response(file_serializer.data, status=status.HTTP_201_CREATED) |
| ... | @@ -66,6 +68,8 @@ class FileDetail(APIView): | ... | @@ -66,6 +68,8 @@ class FileDetail(APIView): |
| 66 | file = 'media/'+path.split('/')[-1] | 68 | file = 'media/'+path.split('/')[-1] |
| 67 | user = request.user | 69 | user = request.user |
| 68 | s3_interface.download_file(s3_interface.BUCKET, user.username, file, path) | 70 | s3_interface.download_file(s3_interface.BUCKET, user.username, file, path) |
| 71 | + if os.path.exists(file): | ||
| 72 | + os.remove(file) | ||
| 69 | # TODO error | 73 | # TODO error |
| 70 | return Response({'file': file}) | 74 | return Response({'file': file}) |
| 71 | 75 | ... | ... |
-
Please register or login to post a comment