To upload a file into my project directory which is there on the google appengine,I am trying to use apache streaming API and Google App Engine Virtual File System. Here is what I have been able to do till now :
String path = request.getParameter("Data");
PrintWriter writer = response.getWriter();
try {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if( !isMultipart ) {
writer.println("File cannot be uploaded !");
}
else {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request);
List list = null;
while(iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
String fileName = item.getName();
InputStream stream = item.openStream();
if(item.isFormField()) {
// Process regular form field (input type="text|radio|checkbox|etc", select, etc).
} else {
GaeVFS.setRootPath( getServletContext().getRealPath("/") );
FileSystemManager fsManager = GaeVFS.getManager();
//....NOW WHAT....
}
}
}
I am stuck there in the else block. How to proceed now ? I have to write the file to a directory named uploads in my project.
GAE filesystem is read-only. There is no write access via an API. The only way to change filesystem contents is to update the app via
appcfg.If you need to upload data and store it use Blobstore or Google Cloud Storage.
Upload to blobstore:
Serving a blob:
Registering your servlet:
Referencing blob in your JSP: