Upload A File To An Url?
I need to modify my java Class to allow me to successfully upload a file to the URL within. I want to use the web browser's built-in file upload mechanism. This is what I have don
Solution 1:
Use this class to upload your file...hope this might be helpful to you
publicclassTryFile {
publicstaticvoidmain(String[] ar)throws HttpException, IOException, URISyntaxException {
TryFilet=newTryFile();
t.method();
}
publicvoidmethod()throws HttpException, IOException, URISyntaxException {
Stringurl="http://encodable.com/uploaddemo/";
StringfileName=""; //file name to be uploadedHttpClienthttpclient=newDefaultHttpClient();
HttpPosthttppost=newHttpPost(url);
FileBodyfileContent=newFiSystem.out.println("hello");
StringBodycomment=newStringBody("Filename: " + fileName);
MultipartEntityreqEntity=newMultipartEntity();
reqEntity.addPart("file", fileContent);
httppost.setEntity(reqEntity);
HttpResponseresponse= httpclient.execute(httppost);
HttpEntityresEntity= response.getEntity();
}
}
Solution 2:
I believe what you're going to do is not what Android platform expects from you anyhow. You have to upload your stuff using Android API. You can find some useful information in this thread: Android: upload file with filling out POST body together or other similar ones.
Post a Comment for "Upload A File To An Url?"