コード例 #1
0
def upload():
	if request.method == 'POST' or request.form.get("test", None):
		optExpiresIn = _empty_string_to_none(request.form.get("expires_in", None))
		optDownloadLimit = _empty_string_to_none(request.form.get("download_limit", None))
		optHideAfterLimitExceeded = not not request.form.get("hide_after_limit_exceeded", False)
		optGroup = _empty_string_to_none(request.form.get("group"))

		if request.form.get("local", False) and request.form.get("path", False):
			if "\x00" in request.form["path"]:
				return json.dumps({"result": False})

			normalizedPath = os.path.abspath(request.form["path"]).lstrip("/")
			normalizedFullPath = os.path.join(app.config["UPLOAD_BASE_DIR"], normalizedPath)
			fd = file.store_local(normalizedPath)
			newPath = model.create_path(fd.No, os.path.basename(normalizedFullPath), "Web", optExpiresIn, optDownloadLimit,
				optHideAfterLimitExceeded, optGroup)
		else:
			fp = request.files["file"]
			fd = file.store(fp)
			newPath = model.create_path(fd.No, fp.filename, "Web", optExpiresIn, optDownloadLimit,
				optHideAfterLimitExceeded, optGroup)

		return json.dumps({"result": True, "path": newPath.Path})

	else:
		return render_template("upload.html")
コード例 #2
0
def api_twitpic():
	if not app.config.get("ENABLE_API", False):
		return abort(404)
	elif not model.User.query.filter(model.User.APIKey == request.args["api_key"]).first():
		return abort(403)
	else:
		print request.files
		fp = request.files["media"]
		fileName, fileExtension = os.path.splitext(fp.filename)
		fd = file.store(request.files["media"])
		newPath = model.create_path(fd.No, fp.filename, "Twitpic")
		return "<rsp status=\"ok\"><mediaurl>%s</mediaurl></rsp>" % (request.url_root + newPath.Path + fileExtension)
コード例 #3
0
def api_tweetbot():
	if not app.config.get("ENABLE_API", False):
		return abort(404)
	if not request.form["source"].startswith("Tweetbot for"):
		return abort(404)
	elif not model.User.query.filter(model.User.APIKey == request.args["api_key"]).first():
		return abort(403)
	else:
		print request.files
		fp = request.files["media"]
		fileName, fileExtension = os.path.splitext(fp.filename)
		fd = file.store(request.files["media"])
		newPath = model.create_path(fd.No, fp.filename, "Tweetbot")
		return json.dumps({"url": request.url_root + newPath.Path + fileExtension})