Jquery NodeJS将文件从本地计算机上载到远程服务器
所以我让它在我的本地机器上工作,我可以将文件从路径A上传到路径B 代码如下所示 HTML 它成功地将文件上载到C:/Users/MyName/uploadtesterFile/中 但当我将其更改为远程服务器路径时,它会返回错误、不允许跨设备链接等等Jquery NodeJS将文件从本地计算机上载到远程服务器,jquery,node.js,ajax,Jquery,Node.js,Ajax,所以我让它在我的本地机器上工作,我可以将文件从路径A上传到路径B 代码如下所示 HTML 它成功地将文件上载到C:/Users/MyName/uploadtesterFile/中 但当我将其更改为远程服务器路径时,它会返回错误、不允许跨设备链接等等 有参考资料吗?我正在学习W3Cschool教程。有一个名为的包。它是一个中间件,可以轻松地处理多部分表单和上传数据。它也可以根据我们的需要进行配置 var express = require('express') var multer = requ
有参考资料吗?我正在学习W3Cschool教程。有一个名为的包。它是一个中间件,可以轻松地处理多部分表单和上传数据。它也可以根据我们的需要进行配置
var express = require('express')
var multer = require('multer')
var upload = multer({ dest: 'uploads/' })
var app = express()
app.post('/profile', upload.single('avatar'), function (req, res, next) {
// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
})
app.post('/photos/upload', upload.array('photos', 12), function (req, res, next) {
// req.files is array of `photos` files
// req.body will contain the text fields, if there were any
})
var cpUpload = upload.fields([{ name: 'avatar', maxCount: 1 }, { name: 'gallery', maxCount: 8 }])
app.post('/cool-profile', cpUpload, function (req, res, next) {
// req.files is an object (String -> Array) where fieldname is the key, and the value is array of files
//
// e.g.
// req.files['avatar'][0] -> File
// req.files['gallery'] -> Array
//
// req.body will contain the text fields, if there were any
})
app.post('/fileupload', function (req, res) {
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
var oldpath = files.filetoupload.path;
var newpath = 'C:/Users/MyName/uploadtesterFile/' + files.filetoupload.name;
fs.rename(oldpath, newpath, function (err) {
console.log(err);
if (err) throw err;
res.redirect(req.get('referer'));
});
});
})
var express = require('express')
var multer = require('multer')
var upload = multer({ dest: 'uploads/' })
var app = express()
app.post('/profile', upload.single('avatar'), function (req, res, next) {
// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
})
app.post('/photos/upload', upload.array('photos', 12), function (req, res, next) {
// req.files is array of `photos` files
// req.body will contain the text fields, if there were any
})
var cpUpload = upload.fields([{ name: 'avatar', maxCount: 1 }, { name: 'gallery', maxCount: 8 }])
app.post('/cool-profile', cpUpload, function (req, res, next) {
// req.files is an object (String -> Array) where fieldname is the key, and the value is array of files
//
// e.g.
// req.files['avatar'][0] -> File
// req.files['gallery'] -> Array
//
// req.body will contain the text fields, if there were any
})