类 UploadDirective
java.lang.Object
com.publiccms.common.directive.BaseHttpDirective
com.publiccms.common.base.AbstractAppDirective
com.publiccms.views.directive.api.UploadDirective
- 所有已实现的接口:
Directive,HttpDirective
upload 上传接口
认证头
appToken:应用授权TokenauthToken:用户登录TokenauthUserId:用户id
参数列表
file:文件base64File:文件的base64编码字符串,文件为空时生效originalFilename:文件原名,文件以base64方式上传时需要privatefile:是否私有文件
返回结果
result:上传结果,【true,false】error:错误原因编码fileName:文件路径fileType:文件类型fileSize:文件大小
使用示例
<script>
document.querySelector("input[type=file]").addEventListener("change",function(event) {
var formData = new FormData();
var file = event.target.files[0];
formData.append("file", file);
fetch("${site.dynamicPath}api/upload",{method:"post",headers:{"appToken":"接口访问授权Token""authToken":"用户登录授权","authUserId":"1"},body: formData}).then(res => res.json()).then(data=>{
console.log(result+","+error+","+fileName);
});
});
</script>
-
构造器概要
构造器 -
方法概要
从类继承的方法 com.publiccms.common.base.AbstractAppDirective
execute, getApp, getSite, getUser从类继承的方法 com.publiccms.common.directive.BaseHttpDirective
execute, getName, getNamespace, getShortName, setName, setNamespace, setShortName
-
构造器详细资料
-
UploadDirective
public UploadDirective()
-
-
方法详细资料
-
execute
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, freemarker.template.TemplateException - 指定者:
execute在类中AbstractAppDirective- 参数:
handler-app-user-- 抛出:
IOExceptionfreemarker.template.TemplateException
-
needUserToken
public boolean needUserToken()- 指定者:
needUserToken在类中AbstractAppDirective- 返回:
- whether need the user token
-
needAppToken
public boolean needAppToken()- 指定者:
needAppToken在类中AbstractAppDirective- 返回:
- whether need the app token
-