5

I have a REST web service and android. Now I want to request Http Put using android to call web service. In my REST web service if user want to do Http Put he can request in terminal like this :

curl -H "Content-Type:application/vnd.org.snia.cdmi.dataobject" -v -T /home/student1/a.jpg http://localhost:8080/user1/folder/a.jpg

My question is how to set -T /home/student1/a.jpg in android using HttpPut?

1 Answer 1

8

Here is some snippet you can use:

File f = new File(...);
...
...
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPut httpPut = new HttpPut("http://mydomain.com/some/action");

MultipartEntity entity = new MultipartEntity();
entity.addPart("myFile", new FileBody(f));

httpPut.setEntity(entity);
HttpResponse response  = httpclient.execute(httpPut);
Sign up to request clarification or add additional context in comments.

6 Comments

btw, how to get the file path in File f=new file( file...) from andriod UI?
What do you mean by Android UI? Where is your file?
file is attached from local drive then upload using web service into server system
If anybody can help, I am working around the same problem and have done everything well, but when request is made, it throws exception saying "sendto failed: ECONNRESET (Connection reset by peer)", please help!!
needs external apache jar files. solution without would be nice.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.