0

This is working completely file I want change only "e:/Test/PIC1.JPG" this path. How I write here when I am uploading image from jsp

 public static void main(String[] args) {
            String charset = "UTF-8";
            File uploadFile1 = new File("e:/Test/PIC1.JPG");
            String requestURL = "my url";

            try {
                MultipartUtility multipart = new MultipartUtility(requestURL, charset);

                multipart.addHeaderField("User-Agent", "CodeJava");
                multipart.addHeaderField("Test-Header", "Header-Value");

                multipart.addFormField("description", "Cool Pictures");
                multipart.addFormField("keywords", "Java,upload,Spring");

                multipart.addFilePart("fileUpload", uploadFile1);
                multipart.addFilePart("fileUpload", uploadFile2);

                List<String> response = multipart.finish();

                System.out.println("SERVER REPLIED:");

                for (String line : response) {
                    System.out.println(line);
                }
            } catch (IOException ex) {
                System.err.println(ex);
            }
  • This is *unclear*. Where is a JSP involved in this code? Is your question *how to read a path to later use it in a java program?* (related to shown code) or is it *how to upload a file with a JSP* (related to title) – Serge Ballesta Feb 14 '18 at 08:36

1 Answers1

0

I don't know why all that's in a main but you can check out the accepted answer here;

javax.servlet.http.Part to java.io.File

for a full description of how saving files should work in Java from jsps. You can also create multi part content with javascript and pass the file or file location with the FormData functionality.

https://developer.mozilla.org/en-US/docs/Web/API/FormData

juju
  • 553
  • 1
  • 4
  • 21