-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathtestingapi.py
55 lines (50 loc) · 1.89 KB
/
testingapi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import json, uuid, re
from django.http import response
from django.http.response import JsonResponse
from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.decorators import api_view, parser_classes
from rest_framework import status
import requests
from .db import *
from rest_framework.parsers import MultiPartParser, FormParser
from rest_framework.views import APIView
from django.core.files.storage import default_storage
class Test(APIView):
parser_classes = (
MultiPartParser, FormParser
)
def post(self, request, plugin_id):
files = request.FILES
files = request.FILES.getlist('file')
if len(files)==1:
for file in request.FILES:
file = request.FILES["file"]
filename = default_storage.save(file.name, file)
file_url = default_storage.url(filename)
response = {
"status":200,
"message":"File Upload Successful",
"data" : {
"file_url": file_url,
"status": True
}
}
return Response(response)
elif len(files)>1:
response = {
"status":200,
"message":"File Upload Successful",
"data" : {
"files_info": []
}
}
for file in files:
filename = default_storage.save(file.name, file)
file_url = default_storage.url(filename)
data = {
"original_name": file.name,
"file_url":file_url
}
response["data"]["files_info"].append(data)
return Response(response)