Take the 2-minute tour ×

I am building an application flow where the client uploads a file to a RESTful web service, which saves the file to a default, pre-defined location.

The Java code for REST resource:

public class UploadFile {

    public Response uploadFile(
            @FormDataParam("file") InputStream uploadedInputStream,
            @FormDataParam("file") FormDataContentDisposition fileDetail) {

        String uploadedFileLocation = "D:/uploaded/" + fileDetail.getFileName();

        // save
        writeToFile(uploadedInputStream, uploadedFileLocation);

        // ...

The code for the client side is:

 <form action="http://localhost:8080/file/upload" method="post" enctype="multipart/form-data">
    <p>Select a file : <input type="file" name="file" size="50" /></p>

This works fine for me, but now I want to code it such that the client can decide the location where the file will to be saved. How can I pass this location from the client to the REST service? To receive the parameter we are going to use GET method but in the REST service the POST method is called, hence how can it be done?

share|improve this question
add comment

1 Answer

Add another input in your form to contain the location information and receive as an extra @FormDataParam.

And of course, strictly validate the location otherwise it's a major security risk. I'd personally be tempted to try messing with /etc/passwd :)

share|improve this answer
add comment

Your Answer


