Uploading a file >1MB

82 views
Skip to first unread message

learning coding

unread,
Mar 7, 2012, 10:01:32 AM3/7/12
to Google Web Toolkit, t.br...@gmail.com
Hi all ,

I have to make webapplication using java,
I have to upload a file which is bigger then 1MB .
Actually i need the contentStream of the file and the value of the
textBox which is on the FormPanel ,on the myProject.server side .

The file can be of .txt and .doc type.

Somebody suggested me to use BolbStore.


My Code :

Code
client
// Get The URL
public void onClick(ClickEvent event) {
System.out.println("blob" +blobServices);
blobServices
.getBlobStoreUploadUrl(callback) ;
}
});

//
..Some more code

public void onSubmitComplete(SubmitCompleteEvent event) {

Window.alert(event.getResults());
}

});

The above RPC call is working fine i am able get the URL.
Now i have to use this URL with servlet which is used to upload a
file.

AsyncCallback callback = new AsyncCallback() {

public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
caught.printStackTrace();
}

public void onSuccess(Object result) {
String tmp = result.toString();
uploadForm.setAction(tmp);

// Submit the form to complete the upload
uploadForm.submit();
uploadForm.reset();
}
};

On server Side

public class UploadServiceImpl extends HttpServlet {

BlobstoreService blobstoreService =
BlobstoreServiceFactory.getBlobstoreService();

public void doPost(HttpServletRequest req, HttpServletResponse
res)
throws ServletException, IOException {

Map<String, BlobKey> blobs =
blobstoreService.getUploadedBlobs(req);
BlobKey blobKey = blobs.get("upload");

if(blobKey == null){
res.sendRedirect("/");
}else{
res.sendRedirect("/serve?blob-key=" +blobKey.getKeyString());
}
}

}

With this Code I am able to view only the .txt file on
Window.alert(event.getResults());
and also the size of .txt file is greater then 2 MB.

But when i submit the xyz.doc file it gives option to save file and
also the name of the file xyz.doc is changed to serve.doc
the size of the file is 130 KB.

Plz tell me what to do. file can be of type .txt or .doc with size
greater then 1 MB.

kim young ill

unread,
Mar 8, 2012, 3:29:59 AM3/8/12
to google-we...@googlegroups.com
need to be more specific what your BlobstoreService is doing/used library



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


learning coding

unread,
Mar 8, 2012, 4:25:00 AM3/8/12
to google-we...@googlegroups.com, khi...@googlemail.com
Hi Kim
 
I am very new to GWT .
 
I have to make a web application which uploads the file.
The file can be of type .doc , .txt
The file size can be more then 1 MB.
 
I dont know how to do it.
Some body suggested me to use BolbStore. After suggesting he didnt replied once also.
 
files used for BlobStore

import

javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import

javax.servlet.http.HttpServletRequest;

import

javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobKey;

import

com.google.appengine.api.blobstore.BlobstoreService;

import

com.google.appengine.api.blobstore.BlobstoreServiceFactory;
 
Plz help me . i am stuggling with this from a very long time.
Reply all
Reply to author
Forward
0 new messages