Bläddra i källkod

appInfo update support img upload

chenjunkai 5 år sedan
förälder
incheckning
d85dcf5d54
1 ändrade filer med 16 tillägg och 0 borttagningar
  1. 16 0
      Controller/AppInfo.py

+ 16 - 0
Controller/AppInfo.py

@@ -195,10 +195,12 @@ class AppInfo(View):
         bundleVersion = request_dict.get('bundleVersion', None)
         minAppversion = request_dict.get('minAppversion', None)
         downloadLink = request_dict.get('downloadLink', None)
+        f = self.request.FILES.get('file', None)
         if not all(
                 [appBundleId, appName, systemLanguage, newAppversion, content, app_type, bundleVersion]):
             return response.json(444)
         try:
+
             app_info = App_Info.objects.get(id=id)
             app_info.appBundleId = appBundleId
             app_info.appName = appName
@@ -209,6 +211,20 @@ class AppInfo(View):
             app_info.minAppversion = minAppversion
             app_info.bundleVersion = bundleVersion
             app_info.downloadLink = downloadLink
+            if f:
+                try:
+                    rv_path = 'static/app/image/' + appBundleId + '.png'
+                    as_path = os.path.join(BASE_DIR, rv_path)
+                    if os.path.exists(as_path):
+                        os.remove(as_path)
+                    with open(as_path, 'wb+') as destination:
+                        for chunk in f.chunks():
+                            destination.write(chunk)
+                except Exception as e:
+                    print(repr(e))
+                    pass
+                else:
+                    app_info.img = rv_path
             app_info.save()
         except Exception as e:
             return response.json(404, repr(e))