1

这是我的 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");
}

在我的客户端,我使用 JavaScript 来更改文件的名称:

<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>

在我的 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>

上面的代码在开发机器上工作,但在部署时不工作。可能的错误和解决问题的方法是什么?如何在 appengine 中查看错误?

4

1 回答 1

3

不推荐使用的方法getUploadedBlobs(..) 不支持multiple='true'。尝试getUploads(..)改用。

于 2012-05-23T04:30:35.657 回答