You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Günther Schmidt <gu...@web.de> on 2012/05/25 00:48:42 UTC

Re: Uploading binary data via json - halfway there

Hello,

it seems that it is possible to create an actual valid file node with 
this JSON:

{"sampleFile.pdf":{
     "jcr:primaryType":"nt:file",
     "jcr:content":{
         "jcr:primaryType":"nt:resource",
         "jcr:data":""
     }
}}

However when I filled the jcr:data with base64 encoded binary data it 
seems to have remained base64 encoded on the server side.
I'll give it a couple more tries but even getting this far is nice.

Günther

Re: Uploading binary data via json - halfway there

Posted by Felix Meschberger <fm...@adobe.com>.
Hi,

Problem: Uploading binary along with JSON import in the Sling POST Servlet.

Approach (1):

> Am 24.05.2012 um 22:13 schrieb Günther Schmidt:
>> How would I upload a file via JSON import anyway? Encoding the binary 
>> data as base64? What would the JSON structure have to be?

Approach (2):

> Am 25.05.2012 um 00:44 schrieb Mark Adamcin:
> 
>> Maybe a multipart POST request format could be devised.


I think from the POV of the Sling POST Servlet we could live with both approaches.

The first approach would require additional support in the JSONLoader. This would also benefit the initial content functionality which currently requires a two step approach for JSON and files: JSON for the non-binary structure and plain files for the binary parts.

The second would just require some additional code to the ImportOperation leveraging already present support for file uploads in the POST Servlet.

Opinions ? Takers ?

Regards
Felix



Am 25.05.2012 um 01:07 schrieb David G.:

> Gunter, i assume its storing jcr:data with the the base64 encoded value as a String, right?  
> 
> This is because sling's jsonreader does support detection of string representation of binary objects. (See previous email with link to JSONReader.java)
> 
> When parsing the JSON you're sending in, sling runs down a list of checks to see if it can figure out what property type the property should be -- unfortunately there is no check for Binary, and it will simply fall through and treat the data as a String.
> 
> You wont get around this without a patch, and Mark's approach of supporting multi-form content seems like the best approach (if a change needs to be made, might as well make the one with the most use cases).

> 
> Wish i had better news! JSON import is a pretty great feature though!  
> 
> --  
> David Gonzalez
> Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
> 
> 
> On Thursday, May 24, 2012 at 6:48 PM, Günther Schmidt wrote:
> 
>> Hello,
>> 
>> it seems that it is possible to create an actual valid file node with  
>> this JSON:
>> 
>> {"sampleFile.pdf":{
>> "jcr:primaryType":"nt:file",
>> "jcr:content":{
>> "jcr:primaryType":"nt:resource",
>> "jcr:data":""
>> }
>> }}
>> 
>> However when I filled the jcr:data with base64 encoded binary data it  
>> seems to have remained base64 encoded on the server side.
>> I'll give it a couple more tries but even getting this far is nice.
>> 
>> Günther  
> 


Re: Uploading binary data via json - halfway there

Posted by "David G." <da...@gmail.com>.
Gunter, i assume its storing jcr:data with the the base64 encoded value as a String, right?  

This is because sling's jsonreader does support detection of string representation of binary objects. (See previous email with link to JSONReader.java)

When parsing the JSON you're sending in, sling runs down a list of checks to see if it can figure out what property type the property should be -- unfortunately there is no check for Binary, and it will simply fall through and treat the data as a String.

You wont get around this without a patch, and Mark's approach of supporting multi-form content seems like the best approach (if a change needs to be made, might as well make the one with the most use cases).

Wish i had better news! JSON import is a pretty great feature though!  

--  
David Gonzalez
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Thursday, May 24, 2012 at 6:48 PM, Günther Schmidt wrote:

> Hello,
>  
> it seems that it is possible to create an actual valid file node with  
> this JSON:
>  
> {"sampleFile.pdf":{
> "jcr:primaryType":"nt:file",
> "jcr:content":{
> "jcr:primaryType":"nt:resource",
> "jcr:data":""
> }
> }}
>  
> However when I filled the jcr:data with base64 encoded binary data it  
> seems to have remained base64 encoded on the server side.
> I'll give it a couple more tries but even getting this far is nice.
>  
> Günther