NutzCN Logo
问答 请问有没有使用过ant-design中upload组件上传到nutz后台的
发布于 2206天前 作者 qq_c766893a 2887 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

我前台请求可以发送到后端,但是后端提示

- 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>

这是前台代码

3 回复

那个组件是 ajax 上传的吧?

来自炫酷的 NutzCN

是只能作用于ajax吗?

UploadAdaptor 只是用在普通的form上传。
如果是 Ajax 上传,直接读流就好

来自炫酷的 NutzCN

添加回复
请先登陆
回到顶部