Request Factory and com.google.appengine.api.datastore.Text type

52 views
Skip to first unread message

Sydney

unread,
Sep 10, 2011, 10:14:01 PM9/10/11
to google-we...@googlegroups.com
In my application the user can upload a CSV file to import data. The first implementation was to process the content on the server side. The issue is that it can take more than 30s to process, so I decided to do the processing on the client side. The process consists in extracting data from the file and present them to the user, so he can decide what to import.

With the new implementation the file is uploaded and the content is saved in the datastore as a com.google.appengine.api.datastore.Text. When the upload is done, the client gets the id of an object called ImportResult that contains some information on the uploaded file. Now I want to get the content of that file to process, so I have a RF call to get an ImportResultProxy object: importResultRequest.readById(importId).fire(new Receiver<ImportResultProxy>() {...}). The issue is that the Text type is not valid for a proxy. So I was wondering how you would do to get the content of the uploaded file.

public class ImportResult extends DatastoreObject implements Serializable {
    private Text content;
    @Index
    private Date timestamp;
}

@ProxyFor(value = ImportResult.class, locator = TwigLocator.class)
public interface ImportResultProxy extends EntityProxy {
    Long getId();
    Text getContent();
}

Thomas Broyer

unread,
Sep 11, 2011, 4:41:28 AM9/11/11
to google-we...@googlegroups.com
Can't you simply make your getContent() on ImportResult of type String and "return content.getValue()"?

But actually, if you're doing the processing on the cient-side, how about having the user copy/paste the CSV content in a TextArea rather than upload and re-download it?
(with recent browsers, you can have a FileUpload and get the file's content on the client-side without uploading it to a server; you'd have to use JSNI to detect and then use the feature, but it's IMO really worth it).

Sydney

unread,
Sep 11, 2011, 5:26:19 AM9/11/11
to google-we...@googlegroups.com
The reason is that String are limited to 500 characters in the datastore. Using a TextArea could be a solution. Anyway I would be interested in trying the upload on the client side. Do you ave any pointers on getting the file's content on the client-side. I googled it but found nothing except some .NET Active X solution.

Sydney

unread,
Sep 11, 2011, 5:27:47 AM9/11/11
to google-we...@googlegroups.com
I also found that link that is saying it's not possible. The link is pretty recent: http://stackoverflow.com/questions/6599023/gwt-client-side-file-uploads

Shawn Brown

unread,
Sep 11, 2011, 7:02:34 AM9/11/11
to google-we...@googlegroups.com
> The reason is that String are limited to 500 characters in the datastore.


send a string and convert it before storing

Text text = new Text(someSentString);

...and back out again...

String s = text.getValue();

Shawn

Tobias

unread,
Sep 11, 2011, 2:54:17 PM9/11/11
to google-we...@googlegroups.com
That's not true. I have a picture uploader that resizes the images on the client side before sending it to the server, so that I don't have to bother about users uploading huge photos directly from their camera. Once the user uses drops a file into the page using Drag&Drop or selects it using an <input type="file">, you can read from it on the client side. This works at least with the current WebKit and Firefox engines, haven't tried it with IE though.
To my knowledge, there is no GWT library wrapper for that yet, but it's easy enough to wrap the javascript objects you need with JSNI.
Reply all
Reply to author
Forward
0 new messages