On Wednesday 18 November 2009 20:31:49 Juerg Meier wrote:
> On Tuesday 17 November 2009 23:40:38 Alexander Klimetschek wrote:
> > On Tue, Nov 17, 2009 at 23:21, Juerg Meier <[email protected]> wrote:
> > > On Tuesday 17 November 2009 08:11:18 Felix Meschberger wrote:
> > >> Hi,
> > >>
> > >> Juerg Meier schrieb:
> > >> > Hi all,
> > >> >
> > >> > I wonder if it is possible to upload a file and the pertaining
> > >> > metadata in one pass.
> > >> >
> > >> > I defined a nodetype my:file > nt:file, with an additional multi
> > >> > value string property  'my:tag'.
> > >> >
> > >> > In the post,I do the following:
> > >> >
> > >> > <form....>
> > >> > ...
> > >> >             <input type="file" name="./*" size="80"
> > >> > maxlength="128"/> <input name="my:tag" type="text" >
> > >> >     <input name="my:tag" type="text" >
> > >> >             <input type="hidden" name="./*...@typehint"
> > >> > value="my:file">
> > >>
> > >> My guess is that this should probably be:
> > >>       <input type="hidden" name="jcr:primaryType" value="my:file">
> > >>
> > >> The @TypeHint notation is used to provide property type hints for
> > >> properties. To assign node types a regular jcr:primaryType property
> > >> may be used (and jcr:mixinTypes for mixin node types, if required).
> > >
> > > I had tried the jcr:primaryType option already. It does not show any
> > > effect, that is, I get an nt:file node. With @TypeHint, I get a my:file
> > > node at least. That includes an my:tag property, but this is left
> > > empty, as described above.
> >
> > I think in your case it must be
> >
> >     <input type="hidden" name="./jcr:primaryType" value="my:file">
> >
> > because once you use "./" in any parameter, the Sling post servlet
> > will ignore all parameters that don't start with "./". This is dirty
> > little trick to automatically ignore foreign and unwanted parameters.
> >
> > Regards,
> > Alex
>
> Nop, get again an nt:file instance, also with the trick...
>
> Regards,
> Juerg

That's how it works:

<form....>
...
        <input type="file" name="./*" size="80" maxlength="128"/>
        <input name="./my:tag" type="text" >
        <input name="./my:tag" type="text" >
        <input type="hidden" name="./*...@typehint" value="my:file">
        <input type="hidden" name="sling:resourceType" value="my/content">
        <input type="submit" name="Submit" value="Upload">
</form>

Solution: The tag element's name has to start with an './' as well, otherwise 
it gets ignored by sling. However, the code will not work correctly as shown. 
The problem is that the node name for the file will be computed by sling 
based on the actual file name. Consequently, the tags would be stored in the 
containing node. 

To circumvent this, the tag name (path...) has to be set dynamically on the 
client side, to have it directed to the right place. So I did a small 
javascript which sets the tag name attribute on submission:

<script>
  //get tag + file elements, grab the name of the file to be uploaded
  ...
  tag.name='./' + fileElement.value + '/my:tag';
  ...
</script>

-- Juerg

Reply via email to