Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// check for *.ipynb extension
if (/\.ipynb$/.test(file.originalname)) {
cb(null, true);
} else {
cb(new Error('Wrong file extension. Make sure to upload a Jupyter Notebook file (*.ipynb).'));
}
}
var limits = {
fields: 0,
files: 1,
parts: 1
};
// Use multer disk storage to write uploaded file
var storage = multer.diskStorage({
destination: destination,
filename: filename
});
module.exports = multer({
storage: storage,
fileFilter: fileFilter,
limits: limits
});
console.log(req.body.email);
// move
var destPath = '/root/Public/QuickNote/public/cloud/'+req.body.email+'/'+videoName;
var relPath = '/cloud/'+req.body.email+'/'+videoName;
fs.rename(tmpPath+videoName,destPath, function(err){
if(err){
throw err;
}
});
res.json({code: 200, path: relPath});
});
var audioName;
var audioStorage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, tmpPath);
},
filename: function (req, file, cb) {
var date = new Date();
audioName = "Audio-Recording-"+date.format("yyyy-MM-dd-hh-mm-ss")+".wav";
cb(null, audioName);
}
});
var audioUpload = multer({storage: audioStorage});
app.post("/uploadAudio", audioUpload.any(), function(req, res) {
console.log("audio upload received");
// move
var destPath = '/root/Public/QuickNote/public/cloud/'+req.body.email+'/'+audioName;
var relPath = '/cloud/'+req.body.email+'/'+audioName;
const express = require("express");
const { ObjectID } = require("mongodb");
const moment = require("moment");
const multer = require("multer");
const mime = require("mime-types");
const path = require("path");
const crypto = require("crypto");
const User = require("../models/user");
const middleware = require("../middleware/index");
const Channel = require("../models/channel");
const router = express.Router();
const upload = multer({
storage: multer.diskStorage({
destination: path.join(__dirname, "../public/files/image"),
filename: (req, file, cb)=>{
crypto.pseudoRandomBytes(4, (err, raw)=>{
const mimeType = mime.lookup(file.originalname);
// throw away any extension if provided
const nameSplit = file.originalname.split(".").slice(0, -1);
// nameSplit.pop();
// replace all white spaces with - for safe file name on different filesystem
const name = nameSplit.join(".").replace(/\s/g, "-");
cb(null, raw.toString("hex") + name + "." + mime.extension(mimeType));
});
},
}),
});
var express = require("express");
var router = express.Router();
var Campground = require("../models/campground");
var middleware = require("../middleware");
var request = require("request");
var multer = require('multer');
var storage = multer.diskStorage({
filename: function(req, file, callback) {
callback(null, Date.now() + file.originalname);
}
});
var imageFilter = function (req, file, cb) {
// accept image files only
if (!file.originalname.match(/\.(jpg|jpeg|png|gif)$/i)) {
return cb(new Error('Only image files are allowed!'), false);
}
cb(null, true);
};
var upload = multer({ storage: storage, fileFilter: imageFilter})
var cloudinary = require('cloudinary');
cloudinary.config({
cloud_name: 'learntocodeinfo',
if (process.env['NEWRELIC_LICENSE']) require('newrelic');
var express = require('express');
var passport = require('passport');
var request = require('request');
var multer = require('multer');
var async = require('async');
var cinco = require("../lib/api");
var router = express.Router();
var storageLogoCompany = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'public/uploads')
},
filename: function (req, file, cb) {
cb(null, file.originalname)
}
});
var uploadLogoCompany = multer({ storage: storageLogoCompany });
var cpUploadLogoCompany = uploadLogoCompany.fields([
{name: 'logoCompany', maxCount: 1},
{name: 'board_headshot', maxCount: 1 },
{name: 'technical_headshot', maxCount: 1 },
{name: 'marketing_headshot', maxCount: 1 },
{name: 'finance_headshot', maxCount: 1 },
{name: 'other_headshot', maxCount: 1 }
]);
admin.post('/mods', (req, res, next)=>{
var storage = multer.diskStorage({
destination: (req, file, callback)=>{
callback(null, paths.mods);
},
filename: (req, file, callback)=>{
callback(null, file.originalname);
}
});
var upload = multer({storage: storage}).single('file');
upload(req, res, (err)=>{
if (err) {
return next(err);
}
res.setHeader('Refresh', '1;.')
res.redirect(201, '.');
});
});
export const getRoutes = ({
puppeteerProvider,
getMetrics,
getConfig,
getPressure,
workspaceDir,
disabledFeatures,
}: IGetRoutes): Router => {
const router = Router();
const storage = multer.diskStorage({
destination: (_req, _file, cb) => {
cb(null, workspaceDir);
},
filename: (_req, file, cb) => {
cb(null, file.originalname);
},
});
const upload = multer({ storage }).any();
const config = getConfig();
if (!disabledFeatures.includes(Feature.INTROSPECTION_ENDPOINT)) {
router.get('/introspection', (_req, res) => res.json(hints));
}
if (!disabledFeatures.includes(Feature.METRICS_ENDPOINT)) {
router.get('/metrics', async (_req, res) => res.json(await getMetrics()));
}
//登录和注册需要的User类
var User = require('../models/user');
//发表需要的Post类
var Post = require('../models/post');
//引入留言需要的Comment类
var Comment = require('../models/comment');
//需要引入一个加密的模块
var crypto = require('crypto');
//引入multer插件
var multer = require('multer');
//插件的配置信息
var storage = multer.diskStorage({
//这个是上传图片的地址.
destination:function(req,file,cb){
cb(null,'public/images')
},
//上传到服务器上图片的名字.
filename:function(req,file,cb){
cb(null,file.originalname)
}
})
var upload = multer({storage:storage,size:10225});
//一个权限的问题?
//1.用户未登录的情况下,是无法访问/post ,/logout的
//2.用户在登录的情况下,是无法访问/login,/reg 的
//那么,如果才能完成这个权限的问题呢?
return res.status(500).json({
title: 'An error occured',
error: err
});
}
res.status(200).json({
message: 'Form is deleted',
obj: result
});
})
});
}
}
);
var storage = multer.diskStorage({
destination: function (req, file, cb) {
if (req.user.role[0] === "admin") {
Form.findById((req.params.id), function (err, form){
if (err) {
throw err;
}
var dest = 'server/uploads/forms/' + form.owner;
var stat = null;
try {
stat = fs.statSync(dest);
}
catch (err) {
fs.mkdirSync(dest);
}
if (stat && !stat.isDirectory()) {
throw new Error('Directory cannot be created because an inode of a different type exists at "' + dest + '"');