最终用户通过 Web 应用程序上传文件。我为此使用Blueimp jQuery Fileupload。
在服务器端,我使用强大的管道将上传的文件传输到我正在使用的基于云的文件服务。
代码如下 -
//The function called when file is uploaded
function (req, res) {
var form = new formidable.IncomingForm();
form.parse(req);
form.on('file', function (name, file) {
//Code that uploads the file to the cloud based hosting service
//Once uploaded, we return with the response
res.send(201, data)
});
}
但是,上传到基于云的托管服务的代码需要时间(取决于文件大小)。我想做的是立即返回,而不是等待文件上传到云端。也就是说,可以说是在后台进行上传到云端。
如果我移动事件的res.send(201, data)
外部file
并将其放在函数的末尾,我会收到“请求超时 - 连接关闭且没有响应”错误。
如何在“后台”携带上传并立即返回?