从机器人发送图像和视频文件到服务器并接收处理 [英] Send image and videos files from android to a server and receive processed

查看:194
本文介绍了从机器人发送图像和视频文件到服务器并接收处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Android手机发送视频/图像传输到服务器,并收到处理的视频/图像。 (例如,我发送图像,并收到此图像二值图像或灰度或调整大小等)
什么是做到这一点的家伙最好的和最简单的方法? HTTP?接? XML?怎么办呢?

I want to send video/images from the android mobile to a server and recieve the video/image processed. (For example, I send an image and recieve this image as binary image or gray scale or resized, etc) What's the best and easiest way to do it guys? Http? Sockets? XML? And how to do it?

我是想通过流做到这一点(<一个href=\"http://stackoverflow.com/questions/11248509/shared-library-not-found-error-on-android-logcat\">Shared库没有发现在Android LogCat中错误),但我无法管理如何做到这一点为好。

I was trying to do it by stream (Shared Library not found error on android LogCat) but I couldn't manage how to do it as well.

在此先感谢

推荐答案

首先,这里有一些一般性咨询回答你的问题的特定部分前:

First, here are some general advices before answering specific parts of your question:

尝试做设备上的琐碎的事情。只是把口罩的图像或旋转/缩放这是很琐碎,可以在设备上进行。这样一来,用户并不需要上传任何东西(和的),你的服务器是不是重仓。

Try to do the trivial things on the device. Just putting a mask on an image or rotating/resizing it is very trivial and can be performed on the device. This way, the user does not need to upload anything (and wait) and your server isn't as heavily loaded.

视频和图片能够做大。考虑到这一点。我想到的一个想法是,用户应该上传图像/视频只是一次,而是应该能够下载的最后的结果之前执行多个操作。否则,你将有漫长的等待,时间和高流量结束。

Videos and pictures can grow big. Take this into account. An idea that comes to mind is, that a user should upload the image/video just once, but should be able to perform multiple manipulations before downloading the final result. Otherwise, you'll end up with long waiting-times and high traffic.

告诉你的用户!如果你真的开始上传到自己的服务器(也许是个人的)照片/视频,请确保您使用的最大的安全性就可以得到(SSL应该是一种必须 - 有),并告诉你的用户,你会上传自己的内容到你的服务器。此外,你应该给他们拒绝在该选项,否则,你可能会面临诉讼。

Tell your users! If you really start uploading (maybe personal) pictures/videos to your own Server, ensure that you're using the maximal security you can get (SSL should be a must-have) and tell your users that you'll upload their content to your server. Also, you should give them the option to decline on that, otherwise, you might face a lawsuit.

现在,到它的技术部分:

Now, to the technical part of it:

有关工作流上/从服务器下载文件到/几乎总是相同的:

The workflow for up-/downloading files to/from a server is almost always the same:


  • 打开到服务器的连接,使用 插座

  • 获取你的文件的Stream(在你的情况下,的 的FileInputStream

  • 阅读二进制数据块在字节 -array

  • 从套接字写入读取数据块到输出流

  • 当您完成后,关闭流,然后插槽

  • Open a connection to your server, using a Socket
  • Get a Stream on your file (in your case, a FileInputStream)
  • Read chunks of binary data in a byte-array
  • Write the read chunks to the output stream from the Socket
  • When you're done, close the streams and then the socket

在您的服务器,你做它周围的其他方法和读取从InputStream,写的内容到的 的FileOutputStream

On your server, you do it the other way around and read from the InputStream, writing the content to a FileOutputStream.

下面是如何可以看一个小例子:

Here is a small example of how this can look:

Socket server = new Socket("192.168.178.32", 1337);
OutputStream outputStream = server.getOutputStream();
FileInputStream in = null;
try {
    in = new FileInputStream("/some/path/to/gras.jpeg");
    // Write to the stream:
    byte[] buffer = new byte[1024]; // 1KB buffer size
    int length = 0;
    while ( (length = in.read(buffer, 0, buffer.length)) != -1 ){
        outputStream.write(buffer, 0, length);
    }
    outputStream.flush();
} finally {
    if (in != null) in.close();
    socket.close(); // Will close the outputStream, too.
}

这code驳回​​的事实,有异常可能被抛出这里。你需要处理这些以划拨方式。

This code dismisses the fact that there are exception which might be thrown here. You'll need to handle those in an appropriated way.

你应该考虑到的东西是,用户可能会从移动互联网连接,它可以(通过隧道时会为例)被截获载他们的内容。在这种情况下,你要执行上载/下载是可恢复的。

Something which you should take into account is, that users might upload their content from a mobile internet connection, which can be intercepted (for example when going through a tunnel). In this case, you'll want to implement the up/download to be resumable.

这篇关于从机器人发送图像和视频文件到服务器并接收处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆