我前台请求可以发送到后端,但是后端提示
- Fail to find the firstBoundary (------WebKitFormBoundaryVn934b3XryqXIuke) in stream, quit!
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:imageUpload"})
@POST
@At("")
@Ok("json")
public Object image(@Param("image") TempFile tf, HttpServletRequest req, AdaptorErrorContext err) {
try {
System.out.println(tf);
System.out.println(req);
System.out.println(err);
if (err != null && err.getAdaptorErr() != null) {
return NutMap.NEW().addv("code", 1).addv("msg", "文件不合法");
} else if (tf == null) {
return Result.error("空文件");
} else {
StringBuffer imagePath = new StringBuffer();
imagePath.append("/image/");
imagePath.append(DateUtil.format(new Date(), "yyyyMMdd"));
imagePath.append("/");
imagePath.append(R.UU32() );
imagePath.append(tf.getSubmittedFileName().substring(tf.getSubmittedFileName().lastIndexOf(".")) );
StringBuffer imageFile = new StringBuffer(Globals.AppCustomUploadPath);
imageFile.append(imagePath);
Files.write(new File(imageFile.toString()), tf.getInputStream());
return Result.success("上传成功", imagePath);
}
} catch (Exception e) {
return Result.error("系统错误");
} catch (Throwable e) {
return Result.error("图片格式错误");
}
}
这是后台代码
<FormItem
{...formItemLayout}
label="上传身份证照片"
extra="点击上传身份证照片"
>
{form.getFieldDecorator('image', {
valuePropName: 'file',
getValueFromEvent: normFile,
})(
<Upload
name="image"
action="/api/upload"
onPreview={handlePreview}
listType="picture-card"
>
{uploadButton}
</Upload>
)}
</FormItem>
这是前台代码