[Yanel-dev] Persisting binary data uploaded from a form

Michael Wechner michael.wechner at wyona.com
Fri Oct 8 00:07:08 CEST 2010


  Hi Ioannis

This is part two ;-)

I think it probably helps if you have a look at

YANEL_HOME/src/resources/file/src/java/org/wyona/yanel/impl/resources/node/=
NodeResource.java

(in particular the create(Request) method, which deals with a =

MultipartRequest)
which implements the CreatableV2 interface

http://www.yanel.org/javadoc/org/wyona/yanel/core/api/attributes/CreatableV=
2.html

and also have a look at

YANEL_HOME/src/contributions/resources/resource-creator/src/java/org/wyona/=
yanel/impl/resources/rescreator/ResourceCreatorResource.java

which acts as the "editing tool" making use of the CreatableV2 interface.

The same pattern applies to the CreatableV3 interface, whereas an =

implementation example is

creatable-modifiable-deletable-v3/src/java/org/wyona/yanel/impl/resources/j=
ellyadapterofcmdv3/JellyAdapterForCUDResource.java

or rather

http://svn.wyona.com/repos/public/yanel/contributions/resources/creatable-m=
odifiable-deletable-v3/src/java/org/wyona/yanel/impl/resources/jellyadapter=
ofcmdv3/JellyAdapterForCUDResource.java

Btw, do not trust necessarly the mime type which the browser sends or =

that the suffix corresponds accordingly,
but that's part 3 ;-)

Sometimes people send images with suffix ".gif", but actually these are =

"jpeg" images and for example
IE sends pjpeg (progressive jpeg) which other browsers or image =

libraries, e.g. ImageIO do not understand if
set to pjpeg, but rather needs to be mapped to image/jpeg

Also re maximum upload size please be aware of

http://bugzilla.wyona.com/cgi-bin/bugzilla/show_bug.cgi?id=3D6982

Cheers

Michael

On 10/7/10 6:18 PM, Michael Wechner wrote:
> Hi Ioannis
>
> On 10/6/10 6:29 PM, Ioannis P. Iordanidis wrote:
>> Hi,
>>
>> The resource type that I've written so far for the task of persisting =

>> an Image asset to disk has focused on storing only the text metadata =

>> of the image.
>> These data are entered into a form by an editor.
>>
>> The approach has been to take the metadata from the request =

>> parameters, build an xml document and write that to disk using the =

>> XMLHelper class.
>>
>> Node newNode =3D YarepUtil.addNodes(repository, fullRepoPath, =

>> NodeType.RESOURCE);
>> newNode.setMimeType("application/xml");
>> Document document =3D XMLHelper.createDocument(FOO_NAMESPACE, "Image");
>> XMLHelper.writeDocument(createXmlAsset(document), =

>> newNode.getOutputStream());
>>
>> where the createXMLAsset() method takes care of adding nodes to the =

>> document, each populated from request parameter values.
>
> ok
>>
>> Now my question is: Does anybody know a good approach for taking the =

>> binary data of the uploaded image and persisting that as well?
>
> It's two steps:
>
> 1) One is getting the data via the Request (and to determine its mime =

> type)
> 2) Is persisting the data
>
>
> Re 2) it is very similar to what you have done with the meta data,
>
> Node newImageNode =3D YarepUtil.addNodes(repository, =

> fullRepoPathOfImage, NodeType.RESOURCE);
> newImageNode.setMimeType(image.imageMimeType());
> org.apache.commons.io.IOUtils.copy(image.getInputStream(), =

> newImageNode.getOutputStream());
>
> whereas now the question what is "image" and what do the methods
>
> image#getMimeType()
> image#getInputStream()
>
> do, whereas let me discuss within follow-up email, because I need to =

> get offline
> for a moment and am afraid that I am loosing this part ;-)
>
> Will continue on it shortly.
>
> Cheers
>
> Michael
>
>
>> As the form will have to be submitted using a multipart/form-data =

>> content type, I am anticipating that the approach thus far will be =

>> inadequate.
>>
>> Any help would be much appreciated.
>> Cheers,
>> Ioannis =

>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wyona.org/pipermail/yanel-development/attachments/2010100=
8/290e243e/attachment.htm


More information about the Yanel-development mailing list