• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
file upload action using ERAttachment
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

file upload action using ERAttachment


  • Subject: file upload action using ERAttachment
  • From: Larry Mills-Gahl <email@hidden>
  • Date: Thu, 01 Mar 2012 01:55:38 -0500

I'm working on some workflow automation that takes files from an external process and loads them via curl. 

The following code is working, but it uses a private class com.webobjects.appserver._private.WOInputStreamData to grab the file contents. This makes me think there is probably a better, more WOnderful way of doing this, so if anybody sees problems or easier ways to do what I have here, I would welcome any suggestions. 

This is from a small, scratch application where the Center has many StubFile (which has an ERAttachment named fileAttachment)


public WOActionResults fileUploadAction() {

WOResponse res = new WOResponse();

if (!this.request().formValues().containsKey("centerkey") || !this.request().formValues().containsKey("fileToBeUploaded")) {
res.setStatus(400);
res.appendContentString("<html><head><title>ERROR</title></head><body><h1>Missing Parameters</h1></body></html");
return res;
}

Integer ck = new Integer(this.request().formValueForKey("centerkey").toString());
logger.debug("looking for center with key " + ck);
WOInputStreamData wois = (WOInputStreamData) this.request().formValueForKey("fileToBeUploaded");
String mimeType = (String) this.request().formValueForKey("mimetype");

EOEditingContext ec = ERXEC.newEditingContext();

Center c = (Center) EOUtilities.objectWithPrimaryKeyValue(ec, Center.ENTITY_NAME, ck);
logger.debug("found " + c.name() + " for centerkey " + ck);

StubFile f = (StubFile) EOUtilities.createAndInsertInstance(ec, StubFile.ENTITY_NAME);
f.setCenterId(ck);
f.setCenterRelationship(c);
f.setFilename((String) this.request().formValueForKey("filename"));
f.setTitle((String) this.request().formValueForKey("title"));
try {

NSData fileData = new NSData(wois.bytes());
File up;

up = File.createTempFile("curlupload", "vaws");

FileOutputStream uploadingFile = new FileOutputStream(up);
fileData.writeToStream(uploadingFile);
uploadingFile.close();

ERAttachment attachment = ERAttachmentProcessor.processorForType("file").process(ec, up, null, mimeType, "StubFile.fileAttachment", null);
f.setFileAttachmentRelationship(attachment);
ec.saveChanges();

} catch (IOException e) {

e.printStackTrace();
res.setStatus(501);
res.appendContentString("<html><head><title>ERROR</title></head><body><h1>File Error:</h1><pre>" + e.getMessage() + "</pre></body></html");
return res;
}

res.setStatus(201);
res.appendContentString("<html><head><title>Success</title></head><body><h1>attachment loaded</h1></body></html");

return res;
}




Larry Mills-Gahl
email@hidden



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: login multiple WOApps by passing same login credentials
  • Next by Date: Re: JavaMonitor & wotask SSD Problem.
  • Previous by thread: Re: login multiple WOApps by passing same login credentials
  • Next by thread: Re: Rép : Re: WebObjects 5.4.3 and JavaClient Apps
  • Index(es):
    • Date
    • Thread