Accessing Mime Attachments in Web Scripts

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 06:22 AM
How can I access Mime Attachments when running at HTTP POST or PUT operation on a web script which I am writing to provide a RESTful service to my Alfresco repository?
I am writing a Share Dashlet which needs to deliver generated content (not from a file upload form) to the repository, but I can't find a way in the Web Scripts environment to access POSTed content. Actually, further to that, I'm finding it difficult even to generate the appropriate POST using the "remote" javascript object in Share. At the moment it looks like I'm going to have to literally mock up a mutlipart formdata POST so that I can access the content via the "formdata" Web Script object. This is obviously a terrible way to go about this, so I must be missing something …
Any suggestions greatly appreciated.
Regards
Richard
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 06:49 AM
Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 07:12 AM
Well, the content is being generated elsewhere, and being given to the dashlet upon request. The Dashlet's job is to offer the user the opportunity to store in the repository this externally generated content. Additionally, this is only the tip of the iceberg; I have general requirements to support a RESTful service on my Alfresco repository which will deposit content via HTTP POST, and will contain important information regarding the deposit in the HTTP headers, and which won't have any form data associated with it.
Either way, I don't see what you mean by sending it by HTTP POST and writing it to a file on the server, sorry. Do you mean cache the generated content in some holding space, outside of the repository? That seems like an unnecessary additional step. The problem I'm having with my web scripts is that I don't see how to handle an HTTP POST which /isn't/ a form upload (which is the only practical example of a POST here: http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload).
Cheers,
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 07:51 AM
Well, the content is being generated elsewhere, and being given to the dashlet upon request.So you've got some binary data in your hand..?
The pertinent part of the upload script is
upload.properties.content.write(content)
Now content could come from anywhere - it so happens that to handle a browser-sourced file upload, you get this from parsing multipart-form data. There's no reason why content couldn't come from HTTP POST variable(s), or another node already in the repo.Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 08:35 AM
OK, yes, this is where I'd already got up to. What I'm trying to do is find out how that "content" variable can be populated from a straight mime attachment in the HTTP POST.
What I'm looking for is something like
var content = request.getMimeAttachment()
But of course, there isn't a "request" object in scope, which brings me to the purpose of this post

Cheers,
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 10:00 AM
Thanks,
Mike

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 10:23 AM
Great, thanks very much, that's very helpful. I'll try the quick method of putting the base64 encoded content in as a POST variable, although I have no idea how that scales

I don't suppose (I notice your "Alfresco Engineer" status) that a good feature request would be for more complete HTTP handling to the web scripts, is it? I can't see how as you would write good RESTful web services using the web scripts without these facilities. For example, a number of standards use header fields or even extensions as part of the protocol, which are currently inaccessible to us here.
All the best,
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2008 04:01 PM
We currently process multipart/form, form POST, JSON and CMIS (ATOM) bodies depending on the webscript extension, using different readers. For your case where the file's content is in the body, it makes sense to create a new reader - e.g tied to ".file.js" webscript extensions - which would present the request body's content as a content stream suitable for writing to a file to the JavaScript runtime.
Your other request is for access to arbitrary request headers? This is probably something we can look at as an improvement.
In either case, please raise enhancement issues in JIRA so they can be properly prioritised. Unless you fancy tackling it yourself and contributing back :wink:
Thanks,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2008 12:12 PM
For me, it works with Alfresco 3B, and the form data is in the variable "query".
Then, for example, you can parse it as XML, look into the file "query.post.cmisquery.js" for parsing it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2008 01:42 PM
headers
headersM
The latest HEAD and 3.0E also provide access to the request body via the root object:
requestbody
This object may be used as a parameter to the write method. Also supports the properties content (for converting to a string, if possible), encoding and mimetype.
There are several web script enhancements in 3.0 that have yet to be documented in the wiki. We'll get there as soon as we can because there's some good gems hidden hiding in there.
