""> 9
+from photo.models import PhotosInfo
10
+from photo.serializers import PhotosInfoSerializer
11
+
12
+import os
13
+
14
+
15
+# [How to do a PUT request with curl?](http://stackoverflow.com/questions/13782198/how-to-do-a-put-request-with-curl)
16
+# Unfortunately, the -T is no substitute for -X PUT if you want to specify parameters with -d or -F.
17
+# -T sends the content of a file via PUT. To achieve the GET after a redirect, add the parameter --location
18
+#
19
+# -F, --form <name=content>
20
+#               (HTTP)  This  lets  curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data
21
+#               using the Content-Type multipart/form-data according to RFC 2388. This enables uploading of binary files  etc.  To  force  the
22
+#               'content'  part  to  be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file
23
+#               name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file  upload,
24
+#               while the < makes a text field and just get the contents for that text field from a file.
25
+#
26
+# curl -X POST -F lensman_id=123 -F session_id=456 -F photo_id=789 -F photo=@7056288a9ddf2db294cf50a943920989.jpg;filename=789 http://xfoto.com.cn/api/photos/upload
27
+def upload_photo(request):
28
+    lensman_id = request.POST.get('lensman_id', '')
29
+    session_id = request.POST.get('session_id', '')
30
+    photo_id = request.POST.get('photo_id', '')
31
+
32
+    photo = request.FILES.get('photo', '')
33
+
34
+    if not (lensman_id and session_id and photo_id and photo):
35
+        return JsonResponse({
36
+            'status': 400,
37
+            'message': u'参数错误',
38
+        })
39
+
40
+    try:
41
+        LensmanInfo.objects.get(lensman_id=lensman_id)
42
+    except LensmanInfo.DoesNotExist:
43
+        return JsonResponse({
44
+            'status': 400,
45
+            'message': u'参数错误',
46
+        })
47
+
48
+    _, extension = os.path.splitext(photo.name)
49
+    photo_path = 'photo/{0}/{1}/{2}{3}'.format(lensman_id, session_id, photo_id, extension)
50
+
51
+    if default_storage.exists(photo_path):
52
+        default_storage.delete(photo_path)
53
+    default_storage.save(photo_path, photo)
54
+
55
+    photo, created = PhotosInfo.objects.get_or_create(
56
+        lensman_id=lensman_id,
57
+        session_id=session_id,
58
+        photo_id=photo_id,
59
+        photo_path=photo_path
60
+    )
61
+
62
+    return JsonResponse({
63
+        'status': 200,
64
+        'message': u'照片上传成功',
65
+        'data': photo.data,
66
+    })
67
+
68
+
69
+class PhotoInfoViewSet(viewsets.ModelViewSet):
70
+    queryset = PhotosInfo.objects.all().order_by('-created_at')
71
+    serializer_class = PhotosInfoSerializer

+ 12 - 0
requirements.txt

@@ -0,0 +1,12 @@
1
+CodeConvert==2.0.3
2
+Django==1.8.4
3
+MySQL-python==1.2.5
4
+TimeConvert==1.0.7
5
+django-shortuuidfield==0.1.3
6
+djangorestframework==3.3.1
7
+ipdb==0.8.1
8
+ipython==4.0.0
9
+pep8==1.6.2
10
+pillow==2.9.0
11
+pytz==2015.7
12
+uWSGI==2.0.11.1

kodo - Gogs: Go Git Service

Нет описания

Brightcells: 597ee33ba6 Pai2 => Kodo лет %!s(int64=8): %!d(string=назад)
..
migrations 3114315824 add pc official website лет %!s(int64=10): %!d(string=назад)
pc 356254dea5 Fix typo error лет %!s(int64=9): %!d(string=назад)
__init__.py 3114315824 add pc official website лет %!s(int64=10): %!d(string=назад)
admin.py fabef63211 set line_length=200 for isort лет %!s(int64=10): %!d(string=назад)
models.py fabef63211 set line_length=200 for isort лет %!s(int64=10): %!d(string=назад)
tests.py fabef63211 set line_length=200 for isort лет %!s(int64=10): %!d(string=назад)
views.py 597ee33ba6 Pai2 => Kodo лет %!s(int64=8): %!d(string=назад)