Javascript 如果大于5MB,Flow.js(在Angular.js中)上载到node.js失败
因此,我有1Mb的默认数据块需要上传,同时有5个数据块需要上传,但是在这些数据块完成后,我的客户端不会发送剩余的数据块。因此最大输出为5Mb,有人知道为什么吗?我没有更改任何其他默认设置,TestChunk已启用 我的节点侧贴子是根据cleversprocket的答案制作的: 我的get端基于:Javascript 如果大于5MB,Flow.js(在Angular.js中)上载到node.js失败,javascript,node.js,angularjs,file-upload,xmlhttprequest,Javascript,Node.js,Angularjs,File Upload,Xmlhttprequest,因此,我有1Mb的默认数据块需要上传,同时有5个数据块需要上传,但是在这些数据块完成后,我的客户端不会发送剩余的数据块。因此最大输出为5Mb,有人知道为什么吗?我没有更改任何其他默认设置,TestChunk已启用 我的节点侧贴子是根据cleversprocket的答案制作的: 我的get端基于: //'found', filename, original_filename, identifier //'not_found', null, null, null $.get = function(r
//'found', filename, original_filename, identifier
//'not_found', null, null, null
$.get = function(req, callback) {
var chunkNumber = req.param('flowChunkNumber', 0);
var chunkSize = req.param('flowChunkSize', 0);
var totalSize = req.param('flowTotalSize', 0);
var identifier = req.param('flowIdentifier', "");
var filename = req.param('flowFilename', "");
if (validateRequest(chunkNumber, chunkSize, totalSize, identifier, filename) == 'valid') {
var chunkFilename = getChunkFilename(chunkNumber, identifier);
fs.exists(chunkFilename, function(exists) {
if (exists) {
callback('found', chunkFilename, filename, identifier);
} else {
callback('not_found', null, null, null);
}
});
} else {
callback('not_found', null, null, null);
}
};
我不明白为什么它不会再次启动,过程是:尝试获取文件块,没有块,回复404,发布块,发布部分完成。每次同步上传x5。
然后它不再上传块,它只是在控制台的某个部分停止。日志并没有解决这个问题
我已经从永久性错误中删除了404,这样应用程序就不会停止,但它仍然会停止
任何帮助都会很好,因为文件有时可能会超过5Mb
谢谢,
乔
编辑完整邮政编码:
客户端设置仅更改mg flow的默认设置:
chunkSize: 1024 * 1024,
forceChunkSize: false,
simultaneousUploads: 5,
singleFile: false,
fileParameterName: 'file',
progressCallbacksInterval: 0, //instant feedback
speedSmoothingFactor: 1,
query: {},
headers: {},
withCredentials: false,
preprocess: null,
method: 'multipart',
prioritizeFirstAndLastChunk: false,
target: '/',
testChunks: true,
generateUniqueIdentifier: null,
maxChunkRetries: undefined,
chunkRetryInterval: undefined,
permanentErrors: [415, 500, 501],
onDropStopPropagation: false
通过将Target选项设置为url(在作用域中是一个动态创建的变量),可以在标记中动态设置Target,因此一旦收到所有区块,就会将其上传到tmp,然后将其移动到讲座目录中,以便于组织和管理,例如删除
i.e. uploadFile/{{module.id}}/{{lecture.id}}
然后服务器端
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
得到
职位
您在flow.write之后调用mv,但应该在flow.write的回调中调用它。mv在flow.write完成之前被调用,因为res.send在此函数中,所以它没有完成
只要试着将res.send移动到调用flow.post的顶部,看看你是否得到了所有的块
exports.fileAddPost = function(req,res){
flow.post(req, function(status, filename, original_filename, identifier, currentTestChunk, numberOfChunks) {
console.log('POST', status, original_filename, identifier);
res.send(200);
...
}
如果这样做有效,那么可能是因为mv不在回调中。将其移动到回调中,但暂时将res.send保留在原来的位置
exports.fileAddPost = function(req,res){
flow.post(req, function(status, filename, original_filename, identifier, currentTestChunk, numberOfChunks) {
...
flow.write(identifier, stream, { onDone: flow.clean }, function(err) {
if (err) {
console.log(err);
}
else {
//call mv() here
}
});
然后在flow.write$.write中向其签名添加回调
$.write = function(identifier, writableStream, options, callback) {
...
//At the bottom of this function, after calling options.onDone(identifier)
if (options.onDone) {
options.onDone(identifier);
{
return callback(null);
您还应该添加错误处理。在if exists{…}之后,您可以添加一个else if!exists&&number==1{return callback'cannotwrite file from chunk,chunk不存在';然后是else块
现在尝试一下,看看是否一切正常。如果正常,则尝试将res.send移回mv函数。如果不正常,则此函数可能不异步。您的帖子是什么样子的?
exports.fileAddPost = function(req,res){
flow.post(req, function(status, filename, original_filename, identifier, currentTestChunk, numberOfChunks) {
...
flow.write(identifier, stream, { onDone: flow.clean }, function(err) {
if (err) {
console.log(err);
}
else {
//call mv() here
}
});
$.write = function(identifier, writableStream, options, callback) {
...
//At the bottom of this function, after calling options.onDone(identifier)
if (options.onDone) {
options.onDone(identifier);
{
return callback(null);