Sending Images And Videos To Server In Android
I am creating an android application for taking photos and videos. After capture images I want to send this image with date and some text to web server. In server side I am making
Solution 1:
You can do this with a Multipart post request:(This way, you dont need to create json)
HttpClientclient=newDefaultHttpClient();
HttpPostpost=newHttpPost(serverURL);
MultipartEntitypostEntity=newMultipartEntity();
Filefile=newFile("Your File path on SD card");
postEntity.addPart("fileupload", newFileBody(file, "image/jpeg"));
postEntity.addPart("loginKey", newStringBody(""+loginKey));
postEntity.addPart("message", newStringBody(message));
postEntity.addPart("token", newStringBody(token));
post.setEntity(postEntity);
response = client.execute(post);
You have to add this mime4j library.
Solution 2:
try this to uplaod text ,image to server in asynctask
FileBodyfilebodyVideo=newFileBody(newFile(
"Sd Card VideoPath"));
FileBodyfilebodyVideo1=newFileBody(newFile("Video Upload url"));
StringBody Title= newStringBody("Put Title Here");
StringBody description= newStringBody("Put Desc Here");
MultipartEntityreqEntity=newMultipartEntity();
reqEntity.addPart("image", filebodyVideo);
multipartContent.addPart("Title", Title);
multipartContent.addPart("Description", description);
httppost.setEntity(multipartContent);
Solution 3:
You can use this code in your asynctask:
Filefile=newFile("Your File path on SD card");
HttpClienthttpclient=newDefaultHttpClient();
HttpPosthttpost=newHttpPost("YourUrl");
MultipartEntityentity=newMultipartEntity();
entity.addPart("YourKey",newStringBody("Your Text"));
entity.addPart("File", newFileBody(file));
httpost.setEntity(entity);
HttpResponseresponse= httpclient.execute(httpost);
Post a Comment for "Sending Images And Videos To Server In Android"