You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Tobias Bocanegra <to...@day.com> on 2008/01/16 09:16:46 UTC

how does ujax handle file uploads?

currently uploaded files are handled like 'normal' fields and their
value is read via the MultipartPostParameter's getString(). the result
is that the properties get the string content of the uploaded files. i
think this is not what people want.

i suggest to implement a default behaviour that creates an 'nt:file'
subnode for that uploaded file if the field name has a trailing slash
(and if the request parameter is a file upload), eg:

<form action="/home/tripod/profile" method="post" enctype="multipart/form-data">
  <input type="file" name="./portrait/" />
</form>

results in:

+ home
  + tripod
    + portrait  [nt:file]
      + jcr:content [nt:resource]
        - jcr:data (data of uploaded file)

without the trailing slash in the values name, it would just create a
binary property.
there might also be the need to store the file directly in a 'nt:resource':

<form action="/home/tripod/profile" method="post" enctype="...">
  <input type="file" name="./portrait/" />
  <input type="hidden" name="./portrait/@TypeHint" value="nt:resource" />
</form>


but this is all a bit magic. we can also go the straight forward way
and address the correct properties:

<form action="/home/tripod/profile" method="post" enctype="...">
  <input type="hidden" name="./portrait/jcr:primaryType" value="nt:file" />
  <input type="hidden" name="./portrait/jcr:content/jcr:primaryType"
value="nt:resource" />
  <input type="file" name="./portrait/jcr:content/jcr:data" />
</form>

there would still be some magic in order to set the jcr:mimeType and
the jcr:lastModified.
WDYT ?

regards, toby
-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: how does ujax handle file uploads?

Posted by Tobias Bocanegra <to...@day.com>.
hi,
i attached a patch of the first version for the fileupload for ujax
post servlet to [0].
i also added some tests.

regards, toby

[0] https://issues.apache.org/jira/browse/SLING-168
-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: how does ujax handle file uploads?

Posted by Tobias Bocanegra <to...@day.com>.
another idea:

if the parent node is a nt:folder, create a nt:file. otherwise create
an nt:resource.
further should the "/*" suffix use the local filename as hint for
creating the new node.

if the file is not specified in the upload, the node must not be deleted.

btw: in the current ujax servlet, it either deletes or creates stuff.
i suggest to do both: delete first and then create stuff.

regards, toby
-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: how does ujax handle file uploads?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Jan 16, 2008 10:27 AM, Tobias Bocanegra <to...@day.com> wrote:
> ...i might be desirable not to have the nt:file node at all, and just the
> nt:resource node....

Ok, got it, agreed.

-Bertrand

Re: how does ujax handle file uploads?

Posted by Tobias Bocanegra <to...@day.com>.
> > ... <input type="hidden" name="./portrait@TypeHint" value="nt:resource"/>
> >
> > would create just the resource node, right?..
>
> Not sure what you mean by "create just the resource node", can you clarify?
i might be desirable not to have the nt:file node at all, and just the
nt:resource node. eg:
+ home
 + tripod
   + portrait nt:resource]
       - jcr:data (data of uploaded file)

regards, toby
-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: how does ujax handle file uploads?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Jan 16, 2008 10:15 AM, Tobias Bocanegra <to...@day.com> wrote:

> >...   <input type="hidden" name="./portrait/@TypeHint" value="jcr:Property"/>
>
>... or:
>  <input type="hidden" name="./portrait@TypeHint" value="BINARY"/>
>
> avoiding potential collision with node types. jcr:Property is more
> likely to be a node type than BINARY...

Right, BINARY is better.

> ... <input type="hidden" name="./portrait@TypeHint" value="nt:resource"/>
>
> would create just the resource node, right?..

Not sure what you mean by "create just the resource node", can you clarify?

-Bertrand

Re: how does ujax handle file uploads?

Posted by Tobias Bocanegra <to...@day.com>.
> Why not make this the default behaviour, without using the "magic
> trailing slash":
right.

> And we could use the @TypeHint if we want to store the file data in a
> binary property, i .e:
>
> <form action="/home/tripod/profile" method="post" enctype="multipart/form-data">
>   <input type="file" name="./portrait" />
>   <input type="hidden" name="./portrait/@TypeHint" value="jcr:Property"/>
> </form>

or:
 <input type="hidden" name="./portrait@TypeHint" value="BINARY"/>

avoiding potential collision with node types. jcr:Property is more
likely to be a node type than BINARY.

and

 <input type="hidden" name="./portrait@TypeHint" value="nt:resource"/>

would create just the resource node, right?


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: how does ujax handle file uploads?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Jan 16, 2008 9:16 AM, Tobias Bocanegra <to...@day.com> wrote:

> ...i suggest to implement a default behaviour that creates an 'nt:file'
> subnode for that uploaded file if the field name has a trailing slash
> (and if the request parameter is a file upload), eg:
>

Why not make this the default behaviour, without using the "magic
trailing slash":

<form action="/home/tripod/profile" method="post" enctype="multipart/form-data">
  <input type="file" name="./portrait/" />
</form>

Would create an nt:file structure as you suggest.

And we could use the @TypeHint if we want to store the file data in a
binary property, i .e:

<form action="/home/tripod/profile" method="post" enctype="multipart/form-data">
  <input type="file" name="./portrait" />
  <input type="hidden" name="./portrait/@TypeHint" value="jcr:Property"/>
</form>

WDYT?

-Bertrand