Google App Engine - Blobstore请求处理不在开发中的生产

时间:2012-03-02 20:16:56

标签: java google-app-engine jsp blob blobstore

我正在使用谷歌应用引擎开发上传表单来上传csv文件。 我目前面临的问题是,在开发环境中,请求操作是正确发送的。

在生产环境中,请求操作似乎有效,尽管两种表单的操作相同。

E.g。

开发

   action="http://localhost:8080/_ah/upload/ag50cy1zY2gtcmVwb3J0c3IbCxIVX19CbG9iVXBsb2FkU2Vzc2lvbl9fGAEM"

生产行动:

    action="http://website.appspot.com/_ah/upload/AMmfu6Yer2BJaT_tW_fmc- PKvHaOHD3pnv5QH6o6d8XQQujbCWg5egbjf2sGxP5_cN6uAyvgDVOn8U40wLLXEvoQcrMDbHQQByJpTlamzBPz_8x8LN2UWKM/ALBNUaYAAAAAT1EmxMkvj7tiS9WAvYAWKPG1sN1DvmMk/"

当我在日志中调查时,开发服务器声明操作是: “/ ag50cy1zY2gtcmVwb3J0c3IbCxIVX19CbG9iVXBsb2FkU2Vzc2lvbl9fGAEM”

生产日志的状态表示操作是: “/ form”(如预期的那样)

两者的代码在下面是相同的。

file:upload.jsp

    <%
               request.getAttribute("message");

                BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
            %>

            <hr/>
            <p>Upload a .csv file to the system.</p>
            <fieldset>
                <legend>Upload File</legend>
                <form action="<%= blobstoreService.createUploadUrl("/upload/form") %>" method="post" enctype="multipart/form-data">
                    <label for="filename_1">File: </label>
                    <input id="filename_1" type="file" id="filename_1" name="file" size="30" onchange="checkInput();" /><br/>
                    <br/>
                    <input type="submit" id="submitBtn" value="Upload File" />
                </form>
            </fieldset>

file:controller.java

    else if (action.equals("/form")) {
            Logger.getLogger(Controller3.class.getName()).log(Level.INFO, action);

            Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(request);
            List<BlobKey> bkList = blobs.get("filename_1");
            BlobKey blobKey = bkList.get(0);

            if (blobKey == null) {
                Logger.getLogger(Controller3.class.getName()).log(Level.WARNING, "Blob null");
                response.sendRedirect("/");
            } else {
                Logger.getLogger(Controller3.class.getName()).log(Level.WARNING, "Blob not null");
                FileService fileService = FileServiceFactory.getFileService();

                // Create a new Blob file with mime-type "text/plain"
                AppEngineFile file = fileService.getBlobFile(blobKey);// Again, different standard Java ways of reading from the channel.
                FileReadChannel readChannel = fileService.openReadChannel(file, false);
                Reader reader1 = new BufferedReader(Channels.newReader(readChannel, "UTF8"));

                char c = ',';
                CSVReader reader = new CSVReader(reader1, c);

                ArrayList<ArrayList<String>> results = reader.getResults();
                ArrayList<String> columns = reader.getColumns();

                request.setAttribute("maxColumns", columns);
                request.setAttribute("csvResults", results);

                //Remove the CSV file from the blobstore now we have used it.
                blobstoreService.delete(blobKey);
                this.getServletContext().setAttribute("csvUploadResults", results);
            }

web.xml已设置为处理请求: / _ah / upload / ,/ upload / ,/ _ah / upload / upload / *

我希望有一个简单的解释(可能存在)为什么代码在生产中有效而在开发中不起作用。

任何帮助都会有很大的帮助。

1 个答案:

答案 0 :(得分:2)

我目前正在与Blobstore搏斗。

我注意到你说: web.xml已设置为处理请求:/ _ah / upload /,/ upload /,/ _ah / upload / upload / *

但是请注意,blobstore处理了添加blob的请求后(通过发布到你的createUploadUrl(“/ upload”)的URL)然后它会在web.xml中调用映射到“/ upload”的YOUR方法。因此,您肯定希望删除对/ _ah / upload /的任何web.xml引用,因为这是blobstore将拦截的内容。

我做了一段时间,并且在没有任何记录的情况下收到服务器错误500.