简体   繁体   English

Androdi将位图从设备上传到C#服务器

[英]androdi upload bitmap to c# server from device

I have a bitmap or lets call it a file that I want to upload to my c# server, this bitmap (file) is captured via camera and saved into the sd card, but I have to no idea how exactly should I send it to my c# server. 我有一个位图,或者称它为要上传到我的C#服务器的文件,该位图(文件)是通过相机捕获的,并保存到sd卡中,但是我不知道我应该如何精确地将其发送到我的C#服务器。 I don't know exactly what should I send in my request and what should be my server function's parameter to receive the file. 我不确切知道我应该在请求中发送什么以及接收文件的服务器功能参数是什么。 Any help would be appreciated. 任何帮助,将不胜感激。

I've found this which shows how to send a file to server but it's using a php server side coding so I couldn't completely understand the process. 我发现展示了如何将文件发送到服务器,但它的使用PHP的服务器端编码,所以我不能完全理解的过程。

I'm not asking for code or anything, just a direction or explanation so I understand the concept. 我不是在索要代码或任何东西,而只是索要方向或解释,因此我理解了这个概念。 Thanks in advance 提前致谢

You need to do the following 您需要执行以下操作

  1. Create a api call that will accept the file and store that file somewhere on the server. 创建一个api调用,该调用将接受该文件并将该文件存储在服务器上的某个位置。
  2. You need to upload the image to the server with the help of the api call by passing the image file in it 您需要在api调用的帮助下通过将图像文件传递到服务器来将图像上传到服务器

Uploading image to server example How do I send a file in Android from a mobile device to server using http? 将图像上传到服务器示例如何使用http将Android中的文件从移动设备发送到服务器?

Refer this for uploading with progress bar 请参考此内容以使用进度条上传

Doesn't need to upload the images, just convert Image into Base64 an then upload this string to the specific field. 不需要上传图像,只需将Image转换为Base64,然后将此字符串上传到特定字段即可。

You can easily upload and retrieve images. 您可以轻松上传和检索图像。

Before pushing it to server, convert your bitmap to string and push it using api. 在将其推送到服务器之前,将位图转换为字符串,然后使用api推送。 and the db field should be BLOB.after uploading the string should be converted back to bitmap and then image(This conversion should be written by api guy). 并且db字段应为BLOB。上传后,字符串应转换回位图,然后转换为图像(此转换应由api guy编写)。

public String BitMapToString(Bitmap bitmap) {
 ByteArrayOutputStream baos=new  ByteArrayOutputStream();
 bitmap.compress(Bitmap.CompressFormat.PNG,100, baos);
 byte [] b=baos.toByteArray();
 String temp=Base64.encodeToString(b, Base64.DEFAULT);
 return temp;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM