0
アンドロイドからバイト配列を取得し、ファイルに変換しようとしています。これはどうすればいいですか?私はまた、明示的なフレームワークを使用しています。 Androidアプリからnodejsでバイト配列を取得してファイルに変換するには
アンドロイドからバイト配列を取得し、ファイルに変換しようとしています。これはどうすればいいですか?私はまた、明示的なフレームワークを使用しています。 Androidアプリからnodejsでバイト配列を取得してファイルに変換するには
あなたは私はあなたが明示を使用していると仮定ノード側では、この
String url = "http://yourserver/file-upload";
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),
"yourfile");
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(
new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
//Do something with response...
} catch (Exception e) {
// show error
}
ような何かをします。あなたはこの
var fs = require('fs');
app.post('/file-upload', function(req, res) {
// get the temporary location of the file
var tmp_path = req.files.yourfile.path;
// set where the file should actually exists - in this case it is in the "images" directory
var target_path = './public/images/' + req.files.yourfile.name;
// move the file from the temporary location to the intended location
fs.rename(tmp_path, target_path, function(err) {
if (err) throw err;
// delete the temporary file, so that the explicitly set temporary upload dir does not get filled with unwanted files
fs.unlink(tmp_path, function() {
if (err) throw err;
res.send('File uploaded to: ' + target_path + ' - ' + req.files.yourfile.size + ' bytes');
});
});
};
は、Androidアプリが掲載されているものを見てすることはconsole.log(req.files)を行いような何かを行うことができます。 req.filesの "yourfile"を置き換えます。 yourfileが正しいプロパティを持っています。
詳細情報を提供できますか?バイト配列をAPIにポストしていますか?あなたは現在どのようなアプローチをとっていますか? – RedJandal
ねえ、私はそれをapiに投稿しています。私は私がちょうどreq.body.bytearrayそしてfs.createwritestream(bitearray) – QwertyKing