def upload_image(self, request): photo = request.FILES.get('file') album_id = request.POST.get('albumId') file_id = get_file_md5(photo) + str(int(time.time())) title = request.POST.get('title', '无标题') if album_id == "" or album_id is None: is_default_album = True else: is_default_album = False new_img = Image(Photo=photo, AlbumId=album_id, FileId=file_id, Name=photo.name, Title=title, IsDefaultAlbum=is_default_album, Size=photo.size) new_img.save() new_img.Path = new_img.Photo.path.decode('utf8') new_img.Name = new_img.Photo.name.decode('utf8') try: new_img.save() except Exception, e: print e