Search code examples
javajspamazon-s3liferayliferay-6

Upload a file form jsp to amazonS3


I want to upload a file from a jsp page using AWS SDK to amazon-s3. But for some reason i cannot send the file in my java class. Can someone explain me how i should do the file passing to the class.

More info:

Let`s say that I have myPage.jsp page and inside I have a form that allows the user to chose a file from his computer:

    <input type="file" name="myFile" /> Please chose a file to upload

and I have upload.java file

    public void UploadDocument(ActionRequest actionRequest, ActionResponse actionResponse) throws   
    IOException, PortletException, AmazonClientException, AmazonServiceException{

        File upFile = new File(actionRequest.getParameter("myFile");
                ...
        //From fere on i make my amazon connection and i ma trying to pass the file
}

but i cannot read the file like that it returns null.

I am using Amazon AWS SDK, Liferay portlets SDK, java and jsp

I hope this is enough information

Any help will be appreciated


Solution

  • Tyr this code

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    String sourceFileName = uploadRequest.getFileName("myFile");
    

    Hope this will help you !!!