def post_activity_upload_imgs(post_type, post_id): app.logger.debug("request:[%s],[%s],[%s]" % (request.headers, request.args, request.json)) app.logger.debug("current_user :%s" % current_user.user_id) app.logger.debug("start upload file") # upload new head portrait to store and update post's url app.logger.debug("files :%s" % request.files) if request.files is None: app.logger.error("missing something:file key is lost") abort(400) img_info = dict() img_urls = [] for one_file in request.files.getlist('file'): post_file = one_file # request.files.get(one_file) # get file and save it to local tmp fname = secure_filename(post_file.filename) ext_name = fname.split('.')[-1] obj_id = str(ObjectId()) pic_name = '%s.%s' % (obj_id, ext_name) localfile = os.path.join(app.config['UPLOAD_FOLDER'], pic_name) app.logger.debug("start upload file to local store:[%s],[%s]" % (pic_name, localfile)) post_file.save(localfile) # upload file to oss pic_url = 'zuohaoshi/%s/%s' % (post_type, post_id) file_url = upload_file_to_store(pic_url, pic_name, localfile) if file_url is None: app.logger.error("file upload failed") abort(400) app.logger.debug("end upload file to store:%s\n" % file_url) # delete local tmp file os.remove(localfile) img_urls.append(file_url) if img_urls: # update post's info img_info['img_urls'] = img_urls ret = Activity.post_activity(current_user.user_id, post_type, img_info, post_id) app.logger.debug("modify post image %s:[%s]\n" % (post_id, ret)) return jsonify(ret)
post_data = request.json if post_data is None: app.logger.error("missing parameters:%s" % post_data) abort(400) # post activity if "token" in post_data: try: del post_data["token"] except Exception, e: app.logger.error("del key error:%s", e) if 'uid' not in post_data: post_data['uid'] = current_user.user_id ret = Activity.post_activity(current_user.user_id, post_type, post_data, post_id=None) app.logger.debug("post activity ret [%s]\n" % ret) return jsonify(ret) @activity_blueprint.route("/<post_type>/<post_id>/upload_imgs", methods=["POST"]) @login_required def post_activity_upload_imgs(post_type, post_id): app.logger.debug("request:[%s],[%s],[%s]" % (request.headers, request.args, request.json)) app.logger.debug("current_user :%s" % current_user.user_id) app.logger.debug("start upload file") # upload new head portrait to store and update post's url app.logger.debug("files :%s" % request.files) if request.files is None: