Skip to content

Commit 563529b

Browse files
committed
Fix error with file uploading
1 parent 721b3ee commit 563529b

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

files/views.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ class FileView(generics.GenericAPIView):
1616

1717
@transaction.atomic
1818
def post(self, request):
19-
"""creates a UserFile object and uploads the file to selectel"""
20-
try:
21-
file_api = FileAPI(request.FILES["file"], request.user)
22-
url, info = file_api.upload()
23-
UserFile.objects.create(
24-
user=request.user,
25-
link=url,
26-
name=info["name"],
27-
size=info["size"],
28-
extension=info["extension"],
29-
mime_type=info["mime_type"],
30-
)
31-
return Response({"url": url}, status=status.HTTP_201_CREATED)
32-
except Exception as error:
33-
print(error)
34-
return Response("Failed to upload file", status=status.HTTP_409_CONFLICT)
19+
"""
20+
Creates a UserFile object and uploads the file to Selectel
21+
"""
22+
23+
file_api = FileAPI(request.FILES["file"], request.user)
24+
url, info = file_api.upload()
25+
UserFile.objects.create(
26+
user=request.user,
27+
link=url,
28+
name=info.name,
29+
size=info.size,
30+
extension=info.extension,
31+
mime_type=info.mime_type,
32+
)
33+
return Response({"url": url}, status=status.HTTP_201_CREATED)
3534

3635

3736
def delete(self, request, *args, **kwargs):

0 commit comments

Comments
 (0)