|
@@ -23,6 +23,8 @@ from apps.account.models import Branch
|
|
|
from apps.WechatApplet.models import WechatApplet
|
|
|
from .base import OrderUpdate
|
|
|
from util.format import Formater
|
|
|
+from util.file_operation import PathAndRename, resizePicture
|
|
|
+from django.http import JsonResponse as DJR
|
|
|
|
|
|
|
|
|
@token_required
|
|
@@ -415,3 +417,35 @@ def activity_code(request):
|
|
|
except Exception as e:
|
|
|
traceback.print_exc()
|
|
|
return JSONError(u'获取失败!')
|
|
|
+
|
|
|
+
|
|
|
+def ueditor_image(request):
|
|
|
+ try:
|
|
|
+ upload_path = PathAndRename("upload/")
|
|
|
+
|
|
|
+ data = {}
|
|
|
+ if request.FILES.getlist('upfile'):
|
|
|
+ document = request.FILES.getlist('upfile')[0]
|
|
|
+ type = document.name.split('.')[-1]
|
|
|
+ name = timezone.now().strftime('%Y%m%d%H%M%S%f')
|
|
|
+ filename = "%s-%s.%s" % (
|
|
|
+ upload_path.path, name, type)
|
|
|
+ filename = filename.lower()
|
|
|
+ full_filename = "%s/%s" % (settings.MEDIA_ROOT, filename)
|
|
|
+ with open(full_filename, 'wb+') as destination:
|
|
|
+ for chunk in document.chunks():
|
|
|
+ destination.write(chunk)
|
|
|
+
|
|
|
+ resizePicture(full_filename, 500)
|
|
|
+ data = {
|
|
|
+ "state": "SUCCESS",
|
|
|
+ "original": "%s.%s" % (name, type),
|
|
|
+ "title": "%s.%s" % (name, type),
|
|
|
+ "url": 'https://jpm.zzly.vip' + settings.MEDIA_URL + filename
|
|
|
+ }
|
|
|
+ return DJR(data, safe=False)
|
|
|
+ except CustomError as e:
|
|
|
+ return JSONError(e.get_error_msg())
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ return JSONError(u'图片上传失败!')
|