NutzCN Logo
问答 @RequestBody byte[] content 用nutz 怎么写?
发布于 2351天前 作者 liumaobudao 2731 次浏览 复制 上一个帖子 下一个帖子
标签:
    @RequestMapping(value="/files/{name}/contents", method= RequestMethod.POST)
    public void postFile(@PathVariable(name = "name") String name, @RequestBody byte[] content) {
11 回复
@Ok("raw")


return bytes;

试了@Ok("raw") 还是取不到content

    /**
     * 保存更新文件
     * @param name
     * @param content
     */
    @RequestMapping(value="/files/{name}/contents", method= RequestMethod.POST)
    public void postFile(@PathVariable(name = "name") String name, @RequestBody byte[] content) {
        // 文件的路径
        String path = filePath + name;
        File file = new File(path);
        FileOutputStream fop = null;
        try {
            if (!file.exists()) {
                file.createNewFile();//构建文件
            }
            fop = new FileOutputStream(file);
            fop.write(content);
            fop.flush();
            System.out.println("------------ save file ------------ ");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fop.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

改的

    /**
     * 保存更新文件
     * @param name
     * @param content
     */
    @At("/files/?/contents")
    @POST
    @Ok("raw")
    public void postFile(@Param("name") String name, byte[] content) {
        // 文件的路径
        String path = filePath + name;
        File file = new File(path);
        FileOutputStream fop = null;
        try {
            if (!file.exists()) {
                file.createNewFile();//构建文件
            }
            fop = new FileOutputStream(file);
            fop.write(content);
            fop.flush();
            System.out.println("------------ save file ------------ ");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fop.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

你这是要下载文件?

还是从请求里面读取数据?

@wendal office online server 在线编辑 office 文件

哦,RequestBody声明个InputStream就行了

@wendal 不懂呢 怎么 写?

public void postFile(InputStream ins) {

}

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