WCF Multipart Custom Class - android

I send a POST request from an Android App using the ION library. The request has some multipart parameters and an attachment file.
Something like this:
.setMultipartParameter("Message", message)
.setMultipartParameter("TextFileName", textFileName)
.setMultipartParameter("TextFileContentBase64Encoded", TextFileContentBase64Encoded)
.setMultipartFile("AttachementFile", fileName)
The problem is that server side(WCF), we have a custom class used for parsing this request that has a Stream for the attachment file, and 3 Strings for other parameters. From my understanding, WCF limits you. You can't parse a custom class that has a Stream and other parameters. You either have a Stream or you have other params.
The question is how can you parse a incoming request that has a stream and other parameters in WCF?
Thanks!

Related

Decode a string encoded with Brotli returned by Android Volley

I'm sending an http request to a website using Volley (POST and StringRequest). The call is correctly executed. However, I can see that the result is a string codified. When seeing the headers of the answer I can see it is encoded in br, which means brotli. How can I decode the answer to later read it as a JSON?
Should I change to OkHttp or another alternative?

Dealing with multipart responses

I'm playing with Amazon Alexa (AVS) and the service mostly sends multipart responses.
For example a response can contain an application/json part associated with an application/octet-stream (MP3 data) part.
For now I don't have any idea the way to write my Retrofit2 service method for it to handle it correctly.
I guess an AlexaMultiPartResponse object here won't work:
#Multipart
#Post("/path")
Call<AlexaMultiPartResponse> getAnswer(#Part("metadata") RequestBody metadata, #Part("audio") RequestBody audio);
Do you have any idea?
Regards.
According to this: https://github.com/square/retrofit/issues/2164 there is no elegant way to do it with Retrofit2.
So I ended up parsing the multipart response with Apache FileUpload MultipartStream (https://commons.apache.org/proper/commons-fileupload/apidocs/org/apache/commons/fileupload/MultipartStream.html)

Post With token_id and Json

Forgive me as I'm new to API driven development. I'm doing a front-end and back-end at the same time and ran into a snag.
On the back-end I accept URL encoded token_id that you may post to create a sessions. Goes like
http://someip:3000/sessions/create?token_id=sometoken
and works.
But now to create a post object the back-end expects a JSON object and a token_id. But reading some documentation for my front-end (android+retrofit) I understand that I can't URL encode a field (my token_id) and send a body as JSON.
Maybe I'm taking the wrong approach. Which path should I take to receive the token_id and a json object at the same time on the back-end?
I understand that I can't URL encode a field (my token_id) and send a
body as JSON.
This is true if you are trying to send POST parameters, because those are sent as the body. But you appear to be using query parameters which are part of the URL. You can use query parameters and JSON body in the same request. Your interface would be something like following, adjusting the body and return types for your particular case.
#POST("/sessions/create")
Call<Response> create(#Query("token_id") String tokenID, #Body MyBodyClass body);

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

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.

Categories

Resources