我正在使用电子来构建一个应用程序,它使用快递在Web服务器中提供多个图像文件。快速检测获取请求
从Android中构建的另一个应用程序,我从服务器获取文件并将文件发布到它。
我没有问题,当Android应用被张贴的文件检测:
app.post('/fileupload', function(req, res) {
alert("post");
var fstream;
req.pipe(req.busboy);
req.busboy.on('file', function (fieldname, file, filename) {
//console.log("Uploading: " + filename);
fstream = fs.createWriteStream(__dirname + '/images/' + filename);
file.pipe(fstream);
fstream.on('close', function() {
res.redirect('back');
});
});
});
但仍然没有成功时,Android应用程序从服务器(它得到他们,但我没有拿到文件检测
app.use(function (req, res, next) {
alert("get");
next();
});
和这一个了:
app.get('/', function (req, res) {
alert("get");
next();
});
方式刷新当它我的输出屏幕),我使用此代码试图
我把该目录中的文件名为图片:
var express = require('express')
var app = express()
app.use(express.static('images'));
app.listen(3000);
编辑
如果我打开一个浏览器相同的URL的Android不饶人,它触发事件并显示警告。为什么在Android打开连接时不会触发?我不知道。 的GET请求Android的代码是:
URL url = new URL(sURL);
HttpURLConnection conection = (HttpURLConnection)url.openConnection();
conection.setRequestMethod("GET");
conection.connect();
int lenghtOfFile = conection.getContentLength();
InputStream inputURL = new BufferedInputStream(url.openStream());
使用类似的console.log(“测试++++++++++++”),而不是警报(),以检查是否请求与服务器的console.log相同 –
取得结果 – takluiper