Skip to Content
To be honest, this was the hard part. I’d never done this before but I knew it was theoretically possible. I dug around SDN and found some code snippets, but it took a while before I could put it together in a manner that made sense.
Here’s the magic bits:
this.propertyMap = new MutablePropertyMap();

this.loggedOnUser = (IUser) request.getUser().getUser(); //figuring out to typecast this was a drag!;
Event event = context.getCurrentEvent();

// grab the file using java.fileinputstream… remembering to use the jsp file context (headache)
FileUpload fileUpload = (FileUpload) context.getComponentForId(“fileUpload”);

if (this.loggedOnUser.isAuthenticated()) {
rContext = new ResourceContext(this.loggedOnUser);
RID aRid = new RID(this.repository); // remember that the repository is case sensitive
try {
IResourceFactory aResourceFactory = ResourceFactory.getInstance();
aCollection = (ICollection) aResourceFactory.getResource(aRid, rContext);
IContent aContent = new Content(this.sourceFileInput, this.mimetype, -1L);
if (aCollection != null) {
aResource = aCollection.createResource(this.resource, this.propertyMap, aContent);
To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. S B
    HI Jason,

    Im using this snippet from your code and Im getting a compile error at the following line :

    FileUpload fileUpload = (FileUpload) context.getComponentForId(“fileUpload”);

    The error is : cannot cast from component to fileUpload.

    Any suggestions will be appreciated.

    (0) 

Leave a Reply