Java 如何使用api framesocket轻松上传文件

Java 如何使用api framesocket轻松上传文件,java,html,servlets,input,upload,Java,Html,Servlets,Input,Upload,代码: Html格式: File f = new File("E:\\image.png"); FileInputStream is = null; HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://www.framesocket.com/api/media/upload.php"); MultipartEntity multipartEntity = new Mul

代码:

Html格式:

File f = new File("E:\\image.png");
FileInputStream is = null;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.framesocket.com/api/media/upload.php");
MultipartEntity multipartEntity = new MultipartEntity();
String fsKey = "***";
String fsSecret = "***";
String fsGatekeeper = "***";        
String mediaFilename = "test";
JSONObject resultJson;
try {
    // Add authentication variables.
    multipartEntity.addPart("key", new StringBody(fsKey));
    multipartEntity.addPart("secret", new StringBody(fsSecret));
    multipartEntity.addPart("sig", new StringBody(md5(fsGatekeeper + "upload")));

// Optionally add title, description, etc.
     multipartEntity.addPart("title", new StringBody("Test"));
    // Add the media file:
    multipartEntity.addPart("media", new InputStreamBody(is = new FileInputStream(f), "E:\\image.png"));

    // Execute POST request.
    httpPost.setEntity(multipartEntity);
    HttpResponse httpResponse = httpClient.execute(httpPost);

    // Handle Response
    HttpEntity httpEntity = httpResponse.getEntity();
    InputStream inputStream = httpEntity.getContent();

    String resultString = convertStreamToString(inputStream);

    resultJson = new JSONObject(resultString);

} catch (Exception e) {

    e.printStackTrace();
}                            

文件上载表格
文件上载:
选择要上载的文件:

我编写web应用程序,将文件上载到framesocket.com。我上传了带有特定路径的文件,例如:
E:\\image.png
。但我想上传文件使用
input type=“file”
或任何其他方式从用户机器动态上传。这有多容易?有什么想法吗

<html>
    <head>
        <title>File Uploading Form</title>
    </head>
    <body>
        <h3>File Upload:</h3>
        Select a file to upload: <br />
        <form action="UploadServlet" method="post"
              enctype="multipart/form-data">
            <input type="file" name="file" size="50" />
            <br />
            <input type="submit" value="Upload File" />
        </form>
    </body>
</html>