English 中文(简体)
Google App 引擎/ Java 中的多个文件上传
原标题:Multiple File Upload in Google App Engine / Java works in Development Machine but not when Deployed

这是我的仆人之一:

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>

上述代码在开发机器中起作用,但部署时无法发挥作用。 问题可能出错和解决办法是什么? 我如何看待应用中的错误?

最佳回答

解析方法 get UploadedBlobs (.) < a href=> https:// developers.google.com/apengine/docs/javadoc/com/google/appengine/api/blobstore/blobstore/blobs%28HtpServlet 不支持 多功能= true 。尝试使用 < a href="https:// developers.gogle.com/appeng/docs/java/javadoc/com/gole/gaogle/apengine/apengine/appi/ api/blobstoreService#getUnloadload%28HttpServplet <%29" rel="\\\code@get >

问题回答

暂无回答




相关问题
How to make logging.debug work on Appengine?

I m having a tough time getting the logging on Appengine working. the statement import logging is flagged as an unrecognized import in my PyDev Appengine project. I suspected that this was just an ...

gqlQuery returns object, want list of keys

Is there a way to convert the GqlQuery object to an array of keys, or is there a way to force the query to return an array of keys? For example: items = db.GqlQuery("SELECT __key__ FROM Items") ...

Integrating Google AppEngine with a Thick Client

I want to make a multi-user client-server solution with Java Swing thick client as a front-end and Google AppEngine (Java one) as a back-end. The problem is that GAE provides only web-based forms for ...

sorl.thumbnail : thumbnail is not a valid tag library?

I am trying to install sorl.thumbnail but am getting the following error message: thumbnail is not a valid tag library: Could not load template library from django.templatetags.thumbnail, No module ...