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

查看:67
本文介绍了在 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);
    });
}

在邮递员中我得到了这个:

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

推荐答案

在使用 Postman 时,尤其是当您测试文件上传时,请确保,

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

  1. 标题中:
    • Content-type 字段已在 Headers 中设置为 multipart/form-data.
  1. in Headers:
    • The Content-type field has been set as multipart/form-data in Headers.
  • form-data 选项应保持默认.
  • 从右侧的下拉列表中选择 File 选项而不是 text.
  • 在占位符为 key 的文本框中键入 File.
  • form-data option should remain as default.
  • Choose File option instead of text from the dropdown on the right side.
  • Type File in the text box where the placeholder is key.

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

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