Monday, 19 August 2013

how to write addFilePart for Bitmap

how to write addFilePart for Bitmap

hi i have a question on how to write httpclient for bitmaps
this is the original code that i got from the internet:
public void addFilePart(String paramName, String fileName, byte[] data)
throws Exception {
os.write( (delimiter + boundary + "\r\n").getBytes());
os.write( ("Content-Disposition: form-data; name=\"" + paramName +
"\"; filename=\"" + fileName + "\"\r\n" ).getBytes());
os.write( ("Content-Type: application/octet-stream\r\n" ).getBytes());
os.write( ("Content-Transfer-Encoding: binary\r\n" ).getBytes());
os.write("\r\n".getBytes());
os.write(data);
os.write("\r\n".getBytes());
}
how do i change the code so that it is
public void addFilePart(String paramName, String fileName, Bitmap b)
throws Exception
This is my Java codes:
HttpClient client = new HttpClient(url);
client.connectForMultipart();
client.addFormPart("param1", param1);
client.addFormPart("param2", param2);
client.addFormPart("param3",param3);
client.addFilePart("file", b);
client.finishMultipart();
String data = client.getResponse();
Bitmap b is the picture that i have chosen from my gallery. Is there a way
to change the code? or do i have to use another method??

No comments:

Post a Comment