Reputation: 244
I'm using google app engine to develop an upload form to upload a csv file. The issue I'm currently having is that in a Development environment the request action is to being sent correctly.
In the production environment the request action seems to work although the action is the same for both forms.
E.g.
Development
action="http://localhost:8080/_ah/upload/ag50cy1zY2gtcmVwb3J0c3IbCxIVX19CbG9iVXBsb2FkU2Vzc2lvbl9fGAEM"
Production action:
action="http://website.appspot.com/_ah/upload/AMmfu6Yer2BJaT_tW_fmc- PKvHaOHD3pnv5QH6o6d8XQQujbCWg5egbjf2sGxP5_cN6uAyvgDVOn8U40wLLXEvoQcrMDbHQQByJpTlamzBPz_8x8LN2UWKM/ALBNUaYAAAAAT1EmxMkvj7tiS9WAvYAWKPG1sN1DvmMk/"
When I investigate within the logs, the development server states the action is: "/ag50cy1zY2gtcmVwb3J0c3IbCxIVX19CbG9iVXBsb2FkU2Vzc2lvbl9fGAEM"
Where as the Production logs state the action is: "/form" (as expected)
The code for both is the same underneath as follows.
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);
}
The web.xml has been setup to to deal with the requests: /_ah/upload/, /upload/, /_ah/upload/upload/*
I'm hoping there is a simple explaination (there probably is) why the code works in production but not in development.
Any assistance will be of great help.
Upvotes: 0
Views: 2194
Reputation: 296
I'm currently wrestling with the Blobstore too.
I note you said: The web.xml has been setup to to deal with the requests: /_ah/upload/, /upload/, /_ah/upload/upload/*
But note that AFTER the blobstore has handled the request to add your blob (by posting to the URL you got createUploadUrl("/upload") ) Then it will call YOUR method mapped to "/upload" in web.xml. So you definitely want to remove any web.xml references to /_ah/upload/ as that is what the blobstore will intercept.
I did that for a while and was getting a server error 500 with no logging whatsoever.
Upvotes: 2