I need to upload multiple files into ipfs from node js.

file(html,angularJS) --> node.js --> IPFS --> ipfs hash save into DB.

I have sent a file from HTML(angularJS) and I got the file in node.js by the help of the multer npm module. With this solutions, the file is uploaded into a node.js server and then from there it is uploaded into IPFS.

Since I'm using azure for my node.js server, I cannot upload files. Is there an alternative approach to upload files into IPFS without uploading them to a node.js server?


<form role="form" ng-submit="uploadComplete(form)" enctype="multipart/form-data" name="form.test">
    <input type="file" id="docName" name="docName" multiple class="form-control" 
           accept=".jpg,.png,.jpeg,.doc,.docx,.pdf" file-model="myFiles($files)"
           placeholder="Enter the docName here" required aria-required="true">


var formData = new FormData();
$scope.myFiles = function ($files) {
    formData.append('img', $files[0]);

// Method for sign up to the kyc system
$scope.uploadComplete = function (form) {
    formData.append('email', $scope.email);
    formData.append('password', $scope.password);                 
    var promise = uploadFileToUrl(formData, uploadUrl);            

var uploadFileToUrl = function (formData, uploadUrl) {
    var deffered = $q.defer();
    $http.post(uploadUrl, formData, {
        transformRequest: angular.identity,
        headers: { 'Content-Type': undefined }
    }).success(function (response) {
    }).error(function (response) {
    return deffered.promise;


var storage = multer.diskStorage({
    destination: './uploads/',
    filename: function (req, file, cb) {
        stData = file.stream;
        cb(null, file.originalname.replace(path.extname(file.originalname), "") + '-' + Date.now() + path.extname(file.originalname))
    stream: function (req, file, cb) {
        cb(null, file.stream);

var upload = multer({ storage: storage });

app.post('/api/user/new', upload.single('img'), (req, res) => {
    if (!req.file) {
        return res.status(422).json({
            error: 'File needs to be provided.'


var createNewUser = function (req, resp,stData) {       
    var filesStreamm = [{
        path: req.file.originalname,
        // content: fs.readFileSync(req.file.path)
        content: ipfs.types.Buffer.from(stData)
        // content: fs.createReadStream(stData) //stData

    var deferred = Q.defer();
    ipfs.add(filesStreamm, function (err, files) {
        if (err || !files) {
            return console.error('ipfs add error', err);
        return resp.json({ status: 'SUCCESS', message: 'Published Succesfully' });

Yeah, you can do. I guess you're using Express.js to handle a request and response If you want to upload a file to the server you need to handle a multipart request. Read the file from the request and use the IPFS node module to upload file content to IPFS.

Currently, I am using http module

Please find below sample code for the same:

// Node server
var http = require('http');
const ipfsAPI = require('ipfs-api');
var formidable = require('formidable');
var fs = require('fs');
http.createServer(function (req, res) {
  if (req.url == '/fileupload') {
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
      var oldpath = files.filetoupload.path;
      var uploadedFile = fs.readFileSync(oldpath);
      var picBuffer = new Buffer(uploadedFile);
      ipfs.files.add(picBuffer, function (err, file) {
          if (err) {
      //TODO Use node ipfs module to save file into network,

If you want to save file into IPFS network, you can look into Infra

Not the answer you're looking for? Browse other questions tagged or ask your own question.