How do I put my file into request body using fetch

I’m following Camunda Rest API tutorial. I’m trying to create a new process is diagram_1.bpmn.
Here is my code. I am trying to put my file into request body like postman

I have tried many times but it still didn’t work! Although I got my req.file successfully

Can you print the form data? Seems like a missmatch between the fields you post and the request parameters specified here.

Best regards

This is my Formdata. Please check it. Thank you very much.

After seeing your more recent post, I’m pretty sure your issue stems from the headers (specifically the boundary). Probably easiest to use headers: form.getHeaders() in your request on line 27.

If that doesn’t do the trick, can you provide your code instead of a screenshot? That way we can copy/paste and attempt to reproduce.

My form.ejs code. My project stucture is as my image. I must take screenshot because I cannot paste my ejs code.

This is my index.js code. I use multer to upload file.

const express = require(“express”);
const app = express();
const multer = require(‘multer’)
const fetch = require(‘node-fetch’);
const FormData = require(‘form-data’);
const fs = require(‘fs’)
app.set(‘view engine’, ‘ejs’)

// routes

var storage = multer.diskStorage({
// destination: function(req,file,cb){
// cb(null,’./upload’)
// },
filename: function (req, file, cb) {
cb(null, file.originalname)

var upload = multer({ storage: storage })’/upload’, upload.single(“file”), async function (req, res) {
formdata = new FormData();
await fetch(“http://localhost:8080/engine-rest/deployment/create”, {
method: ‘POST’,
headers: formdata.getHeaders(),
body: formdata,
redirect: ‘follow’
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log(‘error’, error));

// run app
app.listen(process.env.PORT || 3001, () =>
Example app listening at http://localhost:${process.env.PORT || 3001}

I was able to get this working… the way you have this setup, you’re not streaming the file in memory, you have to grab it from disk from the full path, not just the filename. So this,


should be

1 Like

Thank you very much for your support. I deployed process successfully.