How to use multiparty - 10 common examples

To help you get started, we’ve selected a few multiparty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pouchdb / pouchdb-express-router / lib / routes / document.js View on Github external
app.put('/:db/:id(*)', jsonParser, function (req, res, next) {

    var opts = req.query;

    function onResponse(err, response) {
      if (err) return utils.sendError(res, err);
      utils.sendJSON(res, 201, response);
    }

    if (/^multipart\/related/.test(req.headers['content-type'])) {
      // multipart, assuming it's also new_edits=false for now
      var doc;
      var promise = Promise.resolve();
      var form = new multiparty.Form();
      var attachments = {};
      form.on('error', function (err) {
        return utils.sendError(res, err);
      }).on('field', function (_, field) {
        doc = JSON.parse(field);
      }).on('file', function (_, file) {
        var type = file.headers['content-type'];
        var filename = file.originalFilename;
        promise = promise.then(function () {
          return Promise.promisify(fs.readFile)(file.path);
        }).then(function (body) {
          attachments[filename] = {
            content_type: type,
            data: body
          };
        });
github fffy2366 / image-processing / routes / index.js View on Github external
router.post('/upload',function(req,res){
    var form = new multiparty.Form();
//        res.setHeader('Content-Type','text/html');
//        res.setHeader('charset','utf-8');
    form.parse(req, function(err, fields, files) {
        //res.writeHead(200, {'content-type': 'text/plain'});
        //res.write('received upload:\n\n');
        console.log(fields) ;
        console.log(files) ;
        //res.end(util.inspect({fields: fields, files: files}));
        var limitMaxSize = fields.limitMaxSize ;
        var type = fields.type ;
        //StringUtils.mkdir('./public/uploads/'+type, function(err) {console.log(err);});
        console.log("limitMaxSize:"+limitMaxSize) ;
        console.log("type:"+type) ;
        StringUtils.mkdirSync('../public/uploads/' + type);
        if(err){
            console.log("err:"+err) ;
github prisma-archive / graphcool-templates / outdated / file-handling / file-proxy / extension-file-proxy.js View on Github external
app.post('/:projectId', (req, res) => {
  const webtaskName = req.originalUrl.split('/')[1];
  const projectId = req.params.projectId;
  const graphCoolFileEndpoint = `https://api.graph.cool/file/v1/${projectId}`;
  const graphCoolSimpleEndpoint = `https://api.graph.cool/simple/v1/${projectId}`;

  // We set up a new multiparty form to process our request later on
  const form = new multiparty.Form();

  // Multiparty generates a 'part' event for every file in the request
  // This implementation assumes a single file is posted
  form.on('part', function(part) {

    // We construct a new form for posting to the actual Graphcool File API
    const formdata = new formData();
    // To reduce memory footprint for large file uploads, we use streaming
    formdata.append('data', part, { filename: part.filename, contentType: part['content-type'] });

    // Extract the extension from the filename
    const extension = path.extname(part.filename);

    // Post the constructed form to the Graphcool File API
    request.post(graphCoolFileEndpoint,
      {
github linkedpipes / etl / frontend / server / execution-factory.js View on Github external
"headers": {
      "Content-Type": "multipart/form-data; boundary=" + boundaryString,
      "Transfer-Encoding": "chunked",
      "Accept": "application/json",
      "Connection": "keep-alive"
    }
  };
  let pipePostRequestResponse = true;
  const postRequest = httpRequest(postOptions, (executorMonitorRes) => {
    // Pipe result back to caller if pipePost is true.
    if (pipePostRequestResponse) {
      executorMonitorRes.pipe(res);
    }
  });
  const postStream = new StreamCombiner(postRequest);
  const form = new multiparty.Form();
  let isFirstBoundary = true;
  let configurationAsString = ""; // Default is empty configuration.
  let pipelineAsString = "";
  const shouldUnpackPipeline = !req.query["unpacked_pipeline"];

  form.on("part", (part) => {
    if (part.name === "configuration") {
      part.on("data", (chunk) => configurationAsString += chunk);
      return;
    }
    if (part.name === "pipeline" && shouldUnpackPipeline) {
      part.on("data", chunk => pipelineAsString += chunk);
      return;
    }
    // Pipe all the rest to executor-monitor server.
    const textStream = new PassThrough();
github chejen / keys-translations-manager / src / controllers / ImportController.js View on Github external
.post(function(req, res) {
			form = new multiparty.Form(); //needs to new the form every time
			form.parse(req, function(err, fields, files) {
				importUtil.read(files.file[0].path, function(err, fileType, data){
					if (err) {
						res.status(500).send(err);
					}

					if (fileType === "json") {
						data = json2Properties({}, data, "");
					}

					// check if keys conflict
					locale = fields.locale[0];
					project = fields.project;

					query = [{
						"project": project[0]
github nfriedly / nfriedly.com / node_modules / docpad / node_modules / express / node_modules / connect / lib / middleware / multipart.js View on Github external
limit(req, res, function(err){
      if (err) return next(err);

      var form = new multiparty.Form(options)
        , data = {}
        , files = {}
        , done;

      Object.keys(options).forEach(function(key){
        form[key] = options[key];
      });

      function ondata(name, val, data){
        if (Array.isArray(data[name])) {
          data[name].push(val);
        } else if (data[name]) {
          data[name] = [data[name], val];
        } else {
          data[name] = val;
        }
github Cron-J / Hapi-file-upload-download / server / controller / uploadDownload.js View on Github external
handler: function(requset, reply) {
        var form = new multiparty.Form();
        form.parse(requset.payload, function(err, fields, files) {
            if (err) return reply(err);
            else upload(files, reply);
        });
    }
};
github IvyDev0 / iGraffiti-WechatApp / server / routes / album / handlers / upload.js View on Github external
parseForm() {
        const form = new multiparty.Form({
            encoding: 'utf8',
            maxFilesSize: this.MAX_FILE_SIZE * 1024 * 1024,
            autoFiles: true,
            uploadDir: path.join(global.SERVER_ROOT, 'tmp'),
        });

        return new Promise((resolve, reject) => {
            form.parse(this.req, (err, fields = {}, files = {}) => {
                return err ? reject(err) : resolve({ fields, files });
            });
        });
    }
}
github thinkjs / thinkjs / src / middleware / parse_form_payload.js View on Github external
getFormData(uploadDir){
    let http = this.http;
    let deferred = think.defer();
    let postConfig = think.config('post');
    let form = new multiparty.Form({
      maxFieldsSize: postConfig.max_fields_size,
      maxFields: postConfig.max_fields,
      maxFilesSize: postConfig.max_file_size,
      uploadDir: uploadDir
    });
    //support for file with multiple="multiple"
    let files = http._file;
    form.on('file', (name, value) => {
      if (name in files) {
        if (!think.isArray(files[name])) {
          files[name] = [files[name]];
        }
        files[name].push(value);
      }else{
        files[name] = value;
      }
github mockee / nodecat / router.js View on Github external
app.post('/note/upload_pic', function(req, res) {
    var form = new multiparty.Form({
      uploadDir: utils.getUploadPath()
    })

    form.parse(req, function(err, fields, files) {
      res.header('Content-Type', '')
      res.end('{"src":"' + files.image[0].path + '"}')
    })
  })

multiparty

multipart/form-data parser which supports streaming

MIT
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis

Popular multiparty functions