在POSTMAN上使用PUT/POST方法上传文件

Cup*_*k05 4 javascript request node.js postman

我正在尝试将带有POSTMAN的文件上传到此网址

http://localhost:3000/bucket/test/files/
Run Code Online (Sandbox Code Playgroud)

并且应该在我的控制器中得到结果:

    put(request, response, args) {
    //HERE IN THE REQUEST.BODY 
    console.log(request.body)

    let fileManager = request.modules.VMFile;
    let mimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/x-icon', '  video/mpeg', 'text/html', 'video/x-msvideo', 'application/msword', 'application/pdf', 'application/vnd.ms-powerpoint', 'application/x-rar-compressed'];
    let maxFileSize = 4 * 1024 * 1024;

    fileManager.initUpload(mimeTypes, maxFileSize);

    fileManager.receive((files) => {

        fileManager.forEachFileContent(files, (file, content) => {

            minioClient.putObject(request.body.bucket, request.body.name, content, file.size, file.mimetype, function (err, etag) {
                response.setData("File uploaded").apply();
                return console.log(err, etag)
            })

        });
        fileManager.clearFilesFromTmp(files);
    });
}
Run Code Online (Sandbox Code Playgroud)

在POSTMAN我得到了这个:

邮差

标题上没有任何东西,但我只能PUT(或POST,我试图用POST更改我的路线但同样的问题)名称和存储区字段..我的文件字段没有任何内容..

有什么好主意吗?

Dav*_*d R 15

Postman测试文件上传时特别使用,请确保,

  1. 标题中:
    • Content-type字段已设置为multipart/form-data标题.
  2. 车身:
    • form-data 选项应保留为默认值.
    • 选择File选项而不是text右侧的下拉菜单.
    • 键入File占位符所在的文本框key.

希望这可以帮助!