public class GAEFileService {
public static String createFile(String contentType, String fileName, byte[] content)
throws FileNotFoundException, FinalizationException, LockException, IOException {
FileService fileService = FileServiceFactory.getFileService();
// Create a new Blob file with mime-type "text/plain"
AppEngineFile file = fileService.createNewBlobFile(contentType, fileName);
// Open a channel to write to it
boolean lock = true;
FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
// Different standard Java ways of writing to the channel
// are possible. Here we use a PrintWriter:
writeChannel.write(ByteBuffer.wrap(content));
// Now finalize
writeChannel.closeFinally();
BlobKey key = fileService.getBlobKey(file);
return key.getKeyString();
}