|
17 | 17 | ) |
18 | 18 |
|
19 | 19 |
|
20 | | -class FileUploadView(APIView): |
| 20 | +class FileView(APIView): |
21 | 21 | permission_classes = [permissions.AllowAny] |
22 | 22 |
|
23 | 23 | @transaction.atomic |
@@ -46,17 +46,21 @@ def post(self, request): |
46 | 46 | with file.open(mode="rb") as file_object: |
47 | 47 | r = requests.put( |
48 | 48 | url, |
49 | | - headers={ |
50 | | - "X-Auth-Token": token, |
51 | | - "X-Object-Meta-Content-Type": file_object.content_type, |
52 | | - }, |
53 | | - files={"file": (file.name, file_object, file.content_type)}, |
| 49 | + headers={"X-Auth-Token": token, "Content-Type": file_object.content_type}, |
| 50 | + data=file_object.read(), |
54 | 51 | ) |
55 | 52 | if r.status_code != 201: |
56 | 53 | return Response("Failed to upload file", status=status.HTTP_409_CONFLICT) |
57 | 54 | self._save_to_db(user, url) |
58 | 55 | return Response({"url": url}, status=status.HTTP_201_CREATED) |
59 | 56 |
|
| 57 | + def delete(self, request, pk): |
| 58 | + try: |
| 59 | + UserFile.objects.get(pk=pk).delete() |
| 60 | + except UserFile.DoesNotExist: |
| 61 | + return Response(status=status.HTTP_404_NOT_FOUND) |
| 62 | + return Response(status=status.HTTP_200_OK) |
| 63 | + |
60 | 64 | @classmethod |
61 | 65 | def _save_to_db(cls, user, url): |
62 | 66 | """creates userfile object for file uploads""" |
|
0 commit comments