def uploadImagesFromUeditor(request): if request.method == 'POST' and request.FILES.values(): results = {} for t_file in request.FILES.values(): try: title = request.POST['pictitle'] except MultiValueDictKeyError: title = t_file.name tpath = datetime.now().strftime('%Y/%m/%d/') r_path = os.path.join(settings.MEDIA_ROOT, tpath) tname = datetime.now().strftime('%H%M%S%f') + '%s' % random.randrange(1, 10000)+ '.' + t_file.name.rsplit('.',1)[1] write_file(check_file_path(r_path, tname), t_file, 'wb+') image_path = os.path.join(tpath, tname) blogFiles.objects.create(filename=t_file.name,fileUrl=image_path,uploadTime=datetime.now()) image = Image.open(os.path.join(r_path, tname)) if image.size[0] > 450: thumb_name = 'thumb_'+tname thumb_height = 450/float(image.size[0])*float(image.size[1]) image = image.resize((450, int(thumb_height)), Image.ANTIALIAS) image.save(os.path.join(r_path, thumb_name)) image_path = os.path.join(tpath, thumb_name) results['url'] = image_path results['title'] = title results['state'] = 'SUCCESS' return HttpResponse(simplejson.dumps(results, ensure_ascii = False), mimetype = 'application/json')
def uploadFilesFromUeditor(request): if request.method == 'POST' and request.FILES.values(): results = {} for t_file in request.FILES.values(): try: title = request.POST['pictitle'] except MultiValueDictKeyError: title = t_file.name tpath = datetime.now().strftime('%Y/%m/%d/') r_path = os.path.join(settings.MEDIA_ROOT, tpath) tname = datetime.now().strftime('%H%M%S%f') + '%s' % random.randrange(1, 10000)+ '.' + t_file.name.rsplit('.',1)[1] write_file(check_file_path(r_path, tname), t_file, 'wb+') file_path = os.path.join(tpath, tname) blogFiles.objects.create(filename=t_file.name,fileUrl=file_path,uploadTime=datetime.now()) results['url'] = file_path results['title'] = title results['state'] = 'SUCCESS' return HttpResponse(simplejson.dumps(results, ensure_ascii = False), mimetype = 'application/json')