You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Juerg Meier <jc...@proxymit.net> on 2009/11/16 22:54:07 UTC

file upload with metadata

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">
     	<input type="hidden" name="sling:resourceType" value="my/content">
	<input type="submit" name="Submit" value="Upload">
</form>

Well, the file gets uploaded, but I miss the my:tag values in the newly 
created note. Now I wonder if this is possible at all in one step, or if this 
needs to be done in two steps, i.e. first the upload, then attaching the 
metadata?

Thanks,
Juerg

 

Re: file upload with metadata

Posted by Juerg Meier <jc...@proxymit.net>.
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 <jc...@proxymit.net> 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

Re: file upload with metadata

Posted by Juerg Meier <jc...@proxymit.net>.
On Tuesday 17 November 2009 23:40:38 Alexander Klimetschek wrote:
> On Tue, Nov 17, 2009 at 23:21, Juerg Meier <jc...@proxymit.net> 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



Re: file upload with metadata

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Nov 17, 2009 at 23:21, Juerg Meier <jc...@proxymit.net> 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

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: file upload with metadata

Posted by Juerg Meier <jc...@proxymit.net>.
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. 

>
> HTH
>
> Regards
> Felix
>
> >      	<input type="hidden" name="sling:resourceType" value="my/content">
> > 	<input type="submit" name="Submit" value="Upload">
> > </form>
> >
> > Well, the file gets uploaded, but I miss the my:tag values in the newly
> > created note. Now I wonder if this is possible at all in one step, or if
> > this needs to be done in two steps, i.e. first the upload, then attaching
> > the metadata?
> >
> > Thanks,
> > Juerg



Re: file upload with metadata

Posted by Felix Meschberger <fm...@gmail.com>.
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).

HTH

Regards
Felix


>      	<input type="hidden" name="sling:resourceType" value="my/content">
> 	<input type="submit" name="Submit" value="Upload">
> </form>
> 
> Well, the file gets uploaded, but I miss the my:tag values in the newly 
> created note. Now I wonder if this is possible at all in one step, or if this 
> needs to be done in two steps, i.e. first the upload, then attaching the 
> metadata?
> 
> Thanks,
> Juerg
> 
>  
>