Upload Image From Android to ASp.net Server - android

I am trying to upload image fromandroid to asp.net server.
I am following following procedure.
convert image from bitmap to byte[] yhen byte[] to string and pass this string to the asp.net web service
is this correct way to save image on to the .net server
Please Give the solution to upload image from android to asp.net server
both client and server side code .

The simplest way is convert your bitmap to base64 string :
public String encodeTobase64(Bitmap image)
{
Bitmap immagex=image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
return imageEncoded;
}
after converting ,you can send the string to webservice, on the server side, you must decode this string to an image !
To convert base64 to image on server side,duckduckgo or google will help you :
https://duckduckgo.com
https://www.google.com/search?sclient=psy-ab&site=&source=hp&btnG=Search&q=convert+base64+to+image+ASp.net+Server

Have a look at this tutorial by Microsoft - you'll be able to use the Build the Web Service part for the web service.
For the Android part, you can get inspired by all other questions that try to send a POST request - for example this one.

If not too late, here is my suggested solution:
Server side: you can create a web service or RESTful application on the .NET Framework. Microsoft provides ASP.NET Web API. You can start from their website here
Client side: your Android here. You can refer to some of the following: Volley, Retrofit...
If you want to use Volley, you can refer to some following links:
Working POST Multipart Request with Volley and without HttpEntity
How to send a “multipart/form-data” POST in Android with Volley
Trouble Sending Multipart File with Boundary via Volley
Of course, you can find more available in SO.
Hope this helps!

Related

Problem with decoding Base64 bitmap that sent to server via http request

We are trying to call a post request via HTTP call in android, the library that we are using is Retrofit.
First of all, we encode our Bitmap image to base64 with the following code.
public static String toBase64(Bitmap bitmap) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
return Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT);
}
And then we send our data using Retrofit to our server.
Our backend is written both with Spring and Flask frameworks and both servers behave exactly the same.
We've tried to debug and find the problem. We found that some weird character is added to the request's body sometimes. It is not persistent but sometimes we got errors on server side.
As you can see in the picture some characters are replaced with some weird characters that aren't in UTF-8 charset. Also, we have this issue on iOS platforms too and I should mention that the size of the image is around 1MB.
The 'Content-Type' header is set correctly like content-type: application/json; UTF-8.
I would really appreciate it if someone could help.

How do I use androidHttp to upload multipart video to server

According to the android documentations, I should be using AndroidHttp.HttpTransport instead of Apache as Apache may not be supported in the future, etc. etc. Does anyone know how to use AndroidHttp for sending multipart data to server? I need to upload a video to server along with title, username, timestamp, etc. Thanks for any help.
With apache, the following code works well for uploading multipart video: Android upload video to remote server using HTTP multipart form data

Firebase for Android send and receive images

I am developing an Android application base on chat demo application done by Firebase.
The problem I'm facing is when I want to transfer images, I don't know how to handle the situation.
for sending the image I encode it in Base64 and send it as a string. So how will be the process of decoding to the image again here?
you must try this.
byte[] imageAsBytes = Base64.decode(String,Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(imageAsBytes, 0,imageAsBytes.length);

Sending Image to server in android

In android I am trying to send image to the server.I am using Multipart request. But when I add image in format ByteArray to the Multipart UnsupportedEncodingException occurs.
following is my code.
Do I need to add mime type to request.
If possible please post the complete Sample code.
Try converting the Image to Base64 format string and then sending that string to the server.
Here's the link to convert image to base64 format.
And then at server end decode it.
I done it with the use of MultiPartEntity . Added image as byteArrayBody and done the HTTP request.

Encode XML string to EXI and send it through a websocket

First of all I am using a client-server architecture, android for the client and node.js for the server, they are connected through Socket.io library, so, they are using websockets.
The doubt that I have is that I am generating a XML string with XMLSerializer from Java, I want to encode it to EXI and send it to a server, thus, is it possible doing the encode XML-EXI without using files? directly from string to string? because all examples I see assume that my XML is in a file and I want the output into another file. Another doubt is, can I just send the EXI as string? because I have already established the communication between the client and the server, but they just send strings, I don not if I can sent whole files, in that case, would be any diference on the amount of data sent?
Finally I have solved it, for people with the same problem, the solution is:
String input = methodGivingXMLString();
byte inputBytes[] = input.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(inputBytes);
transmogrifier.encode(new InputSource(in));
For the input, and for the output:
ByteArrayOutputStream result = new ByteArrayOutputStream();
transmogrifier.setOutputStream(result);
note 1: I am using OpenExi library
note 2: The output stream has to be set before calling the encode() method.

Categories

Resources