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
public class TryFile {
public static void main(String[] ar)
throws HttpException, IOException, URISyntaxException {
TryFile t = new TryFile();
t.method();
}
public void method() throws HttpException, IOException, URISyntaxException {
String url = "http://encodable.com/uploaddemo/";
String fileName = ""; //file name to be uploaded
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
FileBody fileContent = new FiSystem.out.println("hello");
StringBody comment = new StringBody("Filename: " + fileName);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("file", fileContent);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = 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?"