'Upload a file with PUT/POST method on POSTMAN
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 :
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...
Solution 1:[1]
You might be doing it right but sometimes POSTMAN does not work well. I wrote an API to accept both text and file.
While invoking service from Postman.
- I set
Content-Typeas"application/json"andAcceptas"application/json". - In body I pass the text and file It was not working, I tried multiple times. I shut down postman and my laptop.
Woke up the next morning hit again and it worked. Below is the image of the working request.
Solution 2:[2]
These words are output when I try to upload an image from form-data. What is the reason, where do I adjust:
This file isn't in your working directory. Teammates you share this request with won't be able to use this file. To make collaboration easier you can setup your working directory in Settings.
Solution 3:[3]
Not all of David's answer worked for me when using express-fileupload. In short, I don't require the Content-Type header when using express-fileupload.
Note, these steps are for npm / express-fileupload / Postman
- Ensure the header
Content-Typeis disabled. Setting this forcesreq.filesto be undefined. - As per Davids answer, use
form-dataand set thekeyto whatever you require, and upload the file. - If you
console.log(req.files.YOUR_KEY)in your express app, you should have an object with the uploaded file, in my casereq.files.file.
Here's what postman should look like (once again, disable the Content-Type header):
Here's the output within the console when using console.log(req.files):
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sabito 錆兎 stands with Ukraine |
| Solution 2 | Abubakr Siddiq |
| Solution 3 | steadweb |




