嗨,伙计们,我目前正在开发一个使用XMLHttpRequest的上传功能。它在网络浏览器上工作得很好,但当我在手机上测试它时,它就不再工作了。以下是在移动平台上选择照片后的错误日志:
E/ as ( 2604):ERROR:layer_tree_host_impl.cc(2121)由于缺少工作上下文而强制零拷贝块初始化。
我已经加了人行横道
下面是我在客户机上的代码:
if(fileInfo.size <= 20000000) {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/uploadSomeWhere', true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
if (xhr.upload) {
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
display.innerText = Math.floor((e.loaded / e.total) * 100) + '%';
bootstrapPB.style.width = Math.floor((e.loaded / e.total) * 100) + '%';
}
}
xhr.upload.onloadstart = function() {
display.innerText = '0%';
bootstrapPB.style.width = '0%';
}
}
xhr.send(fileInfo);
} else {
LocalState.set("mainError", "Please upload a file not more than 20MB");
}在我的服务器上:
WebApp.connectHandlers.use('/uploadSomeWhere',function(req,res){
function makeid()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 10; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
var uniquePhotoId = makeid();
var originalPhoto = "/"+uniquePhotoId+"_original/";
fs.mkdirSync("/home/dating/contents/"+originalPhoto);
var file2 = fs.createWriteStream("/home/dating/contents"+originalPhoto+uniquePhotoId);
file2.on('error',function(error){if(error){
throw new Meteor.Error("Filed to upload image");
}});
file2.on('finish',function(){
res.writeHead(200, {"content-type":"text/html"});
res.end();
});
req.pipe(file2);
// Set timeout to fully capture and convert the image
setTimeout(function(){
imageMagick(file2.path).autoOrient().setFormat("jpg").write(file2.path, function(){
req.pipe(file2);
});
}, 1000);
req._events.close;
});请告诉我哪里出了问题。非常感谢。顺便说一下,我正在使用ReactJS和Meteor创建一个混合移动应用程序。
我不确定xhr不是在发送数据还是服务器没有接受来自xhr的发送数据。
发布于 2016-07-27 09:17:43
在reactjs中使用xhr似乎确实存在问题,所以我所做的事情就是使用FileReader将图像从文件输入转换为缓冲区base64,然后使用服务器中的FS节点将缓冲区base64转换为图像,然后将其上传到目录中。
现在一切都很好:)
https://stackoverflow.com/questions/38581293
复制相似问题