JR Galia
JR Galia

Reputation: 17269

Multiple File Upload in Google App Engine / Java works in Development Machine but not when Deployed

This is part of my servlet:

public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {

    @SuppressWarnings("deprecation")
    Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);

    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    ServletFileUpload upload = new ServletFileUpload();
    FileItemIterator iterator;

    try {
        iterator = upload.getItemIterator(req);
        Picture pic = null;
        PictureAccess access = null;
        while(iterator.hasNext()){
            FileItemStream item = iterator.next(); 

            pic = new Picture( blobs.get(item.getFieldName()).getKeyString() );

            access = new PictureAccess();
            access.addPictures(pic, user.getEmail() );
        }

    } catch (FileUploadException e) {
        e.printStackTrace();
    }

    res.sendRedirect("/user/picture/upload.jsp");
}

In my client side, I used JavaScript to change the names of the file:

<script type="text/javascript">

    function uploadFile() {
        if (window.File && window.FileList) {
            var fd = new FormData();
            var files = document.getElementById('fileToUpload').files;
            for ( var i = 0; i < files.length; i++) {
                fd.append("file" + i, files[i]);
            }
            var xhr = new XMLHttpRequest();
            xhr.open("POST", document.getElementById('uploadForm').action);
            xhr.send(fd);

            alert('already saved');
            document.getElementById('uploadForm').value = '';

        } else {
            document.getElementById('uploadForm').submit(); //no html5
        }
    }

</script>

In my html/jsp:

<form id="uploadForm" enctype="multipart/form-data" method="post" action="<%= blobstoreService.createUploadUrl("/user/uploadPics") %>">
     <input type="file" name="fileToUpload" id="fileToUpload" multiple="multiple" size="5"/>
     <input type="button" onclick="uploadFile();" value="Upload" />
</form>

The above codes works in development machine but not working when deployed. What are the possible error and solution to the problem? How can I see the error in appengine?

Upvotes: 1

Views: 1870

Answers (1)

Peter Knego
Peter Knego

Reputation: 80330

Deprecated method getUploadedBlobs(..) does not support multiple='true'. Try using getUploads(..) instead.

Upvotes: 3

Related Questions