Hi guys I am currently working on an Upload feature that uses XMLHttpRequest
. It works perfectly on web browsers but when I tested it on mobile it does not work anymore. Here is the error log after selecting photo on mobile:
E/chromium( 2604): [ERROR:layer_tree_host_impl.cc(2121)] Forcing
zero-copy tile initialization as worker context is missing
I already added crosswalk
Here is my code on the client:
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");
}
In my server:
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;
});
Please advise what went wrong. Thanks a lot. By the way I am creating a hybrid mobile app using ReactJS and Meteor.
I am not sure if the xhr is not sending data or the server is not
accepting the send data from the xhr
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…