在POSTMAN上使用PUT / POST方法上传文件 [英] Upload a file with PUT/POST method on POSTMAN

查看:1680
本文介绍了在POSTMAN上使用PUT / POST方法上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用POSTMAN将文件上传到此url

I am trying to upload a file with POSTMAN to this url

http://localhost:3000/bucket/test/files/

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

And should got result in my controller there :

    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);
    });
}

在POSTMAN中,我得到了:

In POSTMAN I got this :

标头上没有任何内容,但我只能进行PUT(或POST,我尝试使用POST更改路线,但相同的问题)的名称和存储区字段。.我的文件字段上什么都没有。.

With nothing on headers but I could only PUT (or POST, I tried to change my route with POST but same issue) the name and bucket field.. I got nothing on my files field..

有什么想法吗?

推荐答案

使用邮递员时,尤其是在测试文件上传时,请确保

While using Postman especially when you test file upload please ensure that,


  1. Headers 中:


    • Content-type 字段在标题中设置为 multipart / form-data

  1. in Headers:
    • The Content-type field has been set as multipart/form-data in Headers.

  • form-data 选项应该保留为默认设置。

  • 选择 File 选项,而不要使用 text 右侧的下拉菜单。

  • 键入 File 在文本框中,其中占位符是 key

  • form-data option should be remain as default.
  • Choose File option instead of text from dropdown at the right side.
  • Type File in text box where placeholder is key.

希望这会有所帮助!

这篇关于在POSTMAN上使用PUT / POST方法上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆