download content & encoding

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

download content & encoding

sebastianconcept@gmail.co
Hi guys,

setting an anchor to download a document encodes the content right?

there is a way to make seaside not to encode the document?


PD: the case is about a .csv file that excel opens with all the utf8 diacritics mangled (which hopefully the BOM should fix http://stackoverflow.com/questions/155097/microsoft-excel-mangles-diacritics-in-csv-files)


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

Lukas Renggli
On 23 November 2011 21:38, Sebastian Sastre
<[hidden email]> wrote:
> Hi guys,
> setting an anchor to download a document encodes the content right?
> there is a way to make seaside not to encode the document?
> sebastian
> o/

Set the response to binary.

Lukas


>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>



--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

sebastianconcept@gmail.co
done.

It works.

Note that mime type is text/csv and it will answer false to #isBinary so it needed tweaking there


On Nov 23, 2011, at 7:06 PM, Lukas Renggli wrote:

On 23 November 2011 21:38, Sebastian Sastre
<[hidden email]> wrote:
Hi guys,
setting an anchor to download a document encodes the content right?
there is a way to make seaside not to encode the document?
sebastian
o/

Set the response to binary.

Lukas



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside





--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside





_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

Johan Brichau-2
Sebastian,

I noticed your question and, because we are also exporting csv but never seemed to bump into any encoding problem, I wonder if the following would not work for you.
We are doing it like this:

html anchor
    callback: [self requestContext respond: [ :response |
                                                        response
                                                                attachmentWithFileName: 'yesplan',Date today yyyymmdd,'.csv';
                                                                contentType: (WAMimeType main: 'text' sub: 'csv');
                                                                nextPutAll: (String streamContents: [:str | self exportCSVOn: str])]];

Works for you too?

cheers
Johan

On 24 Nov 2011, at 14:52, Sebastian Sastre wrote:

> done.
>
> It works.
>
> Note that mime type is text/csv and it will answer false to #isBinary so it needed tweaking there
>
> sebastian
>
> o/
>
> On Nov 23, 2011, at 7:06 PM, Lukas Renggli wrote:
>
>> On 23 November 2011 21:38, Sebastian Sastre
>> <[hidden email]> wrote:
>>> Hi guys,
>>> setting an anchor to download a document encodes the content right?
>>> there is a way to make seaside not to encode the document?
>>> sebastian
>>> o/
>>
>> Set the response to binary.
>>
>> Lukas
>>
>>
>>>
>>> _______________________________________________
>>> seaside mailing list
>>> [hidden email]
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>>
>>>
>>
>>
>>
>> --
>> Lukas Renggli
>> www.lukas-renggli.ch
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>
>
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

sebastianconcept@gmail.co
Hi Johan,

if you deal only with ASCII, you are okay

the problem is seen when you have this:  
diacritics + uft8 encoding + excel

what happens is that excel opens the utf8 file with all the diacritics mangled.

Example:
"Descrição" is shown by excel as "Descrição"

I've tried the BOM header but it doesn't work on office for mac so I've just ecoded it in CP1252

PD: see here for details: 


On Nov 24, 2011, at 1:20 PM, Johan Brichau wrote:

Sebastian,

I noticed your question and, because we are also exporting csv but never seemed to bump into any encoding problem, I wonder if the following would not work for you.
We are doing it like this:

html anchor
    callback: [self requestContext respond: [ :response |
response
attachmentWithFileName: 'yesplan',Date today yyyymmdd,'.csv';
contentType: (WAMimeType main: 'text' sub: 'csv');
nextPutAll: (String streamContents: [:str | self exportCSVOn: str])]];

Works for you too?

cheers
Johan

On 24 Nov 2011, at 14:52, Sebastian Sastre wrote:

done.

It works.

Note that mime type is text/csv and it will answer false to #isBinary so it needed tweaking there

sebastian

o/

On Nov 23, 2011, at 7:06 PM, Lukas Renggli wrote:

On 23 November 2011 21:38, Sebastian Sastre
<[hidden email]> wrote:
Hi guys,
setting an anchor to download a document encodes the content right?
there is a way to make seaside not to encode the document?
sebastian
o/

Set the response to binary.

Lukas



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside





--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

Johan Brichau-2
Indeed. 

FYI: you need UTF16 with tab separation instead of commas to make it work cross platform. 


Johan (sent from my mobile)

On 24 Nov 2011, at 17:16, Sebastian Sastre <[hidden email]> wrote:

Hi Johan,

if you deal only with ASCII, you are okay

the problem is seen when you have this:  
diacritics + uft8 encoding + excel

what happens is that excel opens the utf8 file with all the diacritics mangled.

Example:
"Descrição" is shown by excel as "Descrição"

I've tried the BOM header but it doesn't work on office for mac so I've just ecoded it in CP1252

PD: see here for details: 


On Nov 24, 2011, at 1:20 PM, Johan Brichau wrote:

Sebastian,

I noticed your question and, because we are also exporting csv but never seemed to bump into any encoding problem, I wonder if the following would not work for you.
We are doing it like this:

html anchor
    callback: [self requestContext respond: [ :response |
response
attachmentWithFileName: 'yesplan',Date today yyyymmdd,'.csv';
contentType: (WAMimeType main: 'text' sub: 'csv');
nextPutAll: (String streamContents: [:str | self exportCSVOn: str])]];

Works for you too?

cheers
Johan

On 24 Nov 2011, at 14:52, Sebastian Sastre wrote:

done.

It works.

Note that mime type is text/csv and it will answer false to #isBinary so it needed tweaking there

sebastian

o/

On Nov 23, 2011, at 7:06 PM, Lukas Renggli wrote:

On 23 November 2011 21:38, Sebastian Sastre
<[hidden email]> wrote:
Hi guys,
setting an anchor to download a document encodes the content right?
there is a way to make seaside not to encode the document?
sebastian
o/

Set the response to binary.

Lukas



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside





--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

sebastianconcept@gmail.co
On Nov 24, 2011, at 2:24 PM, Johan Brichau wrote:
you need UTF16 with tab separation instead of commas to make it work cross platform. 

ha! nice one

thanks for that tip


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

Johan Brichau-2
Sebastian,

I even have code for it that should work in Pharo (see below).
I had it in comments in our application code because it does not work in Gemstone (no utf16 encoder).

But if I remember correctly, this works for cross-platform csv import in Excel. Just mind that you need to use tabs to separate the fields instead of commas (or semicolons ;-)

Hope this helps
Johan



                                                        response
                                                                attachmentWithFileName: 'nextplan',Date today yyyymmdd,'.csv';
                                                                contentType: ((WAMimeType main: 'text' sub: 'csv')
                                                                                        charset: 'utf-16');
                                                                binary.
                                                                converter := UTF16TextConverter new useLittleEndian: true; useByteOrderMark: true.
                                                                response nextPutAll: ((String streamContents: [:str |
                                                                                         self exportCSVFor: coll on: str]) convertToWithConverter: converter) asByteArray]];

On 24 Nov 2011, at 18:08, Sebastian Sastre wrote:

> On Nov 24, 2011, at 2:24 PM, Johan Brichau wrote:
>> you need UTF16 with tab separation instead of commas to make it work cross platform.
>
> ha! nice one
>
> thanks for that tip
>
> sebastian
>
> o/
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

sebastianconcept@gmail.co
yes yes it worked at first try. I used to have semicolons as separators but tabs are a better default from the excel's expectation POV.

The usability result is one double click vs. a double click plus a wizard with 3 steps 

so tabs won hands down :)

again, great tip, thanks!


o/



On Nov 25, 2011, at 7:35 AM, Johan Brichau wrote:

Sebastian,

I even have code for it that should work in Pharo (see below).
I had it in comments in our application code because it does not work in Gemstone (no utf16 encoder).

But if I remember correctly, this works for cross-platform csv import in Excel. Just mind that you need to use tabs to separate the fields instead of commas (or semicolons ;-)

Hope this helps
Johan



response
attachmentWithFileName: 'nextplan',Date today yyyymmdd,'.csv';
contentType: ((WAMimeType main: 'text' sub: 'csv')
charset: 'utf-16');
binary.
converter := UTF16TextConverter new useLittleEndian: true; useByteOrderMark: true.
response nextPutAll: ((String streamContents: [:str |
self exportCSVFor: coll on: str]) convertToWithConverter: converter) asByteArray]];

On 24 Nov 2011, at 18:08, Sebastian Sastre wrote:

On Nov 24, 2011, at 2:24 PM, Johan Brichau wrote:
you need UTF16 with tab separation instead of commas to make it work cross platform.

ha! nice one

thanks for that tip

sebastian

o/

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside





_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

Sven Van Caekenberghe
In reply to this post by Johan Brichau-2
Johan,

On 25 Nov 2011, at 10:35, Johan Brichau wrote:

> response
> attachmentWithFileName: 'nextplan',Date today yyyymmdd,'.csv';
> contentType: ((WAMimeType main: 'text' sub: 'csv')
> charset: 'utf-16');
> binary.
> converter := UTF16TextConverter new useLittleEndian: true; useByteOrderMark: true.
> response nextPutAll: ((String streamContents: [:str |
> self exportCSVFor: coll on: str]) convertToWithConverter: converter) asByteArray]];

Just out of curiosity: why did you chose to encode using UTF-16 instead of the much more common, quasi standard UTF-8 ?

Sven

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

Johan Brichau-2
Hi Sven,

> Just out of curiosity: why did you chose to encode using UTF-16 instead of the much more common, quasi standard UTF-8 ?

It's an Excel thing.

UTF16 is required for a csv file to be opened correctly by excel on both windows and mac platforms
The csv file also needs to use tabs as separators to make it work correctly.

UTF8 does not work for Excel in that case.

I cannot remember where I puzzled that information together, but I do remember it's one of those things that took a long time to find out…

Johan_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

Sven Van Caekenberghe

On 25 Nov 2011, at 13:47, Johan Brichau wrote:

> It's an Excel thing.
>
> UTF16 is required for a csv file to be opened correctly by excel on both windows and mac platforms
> The csv file also needs to use tabs as separators to make it work correctly.
>
> UTF8 does not work for Excel in that case.
>
> I cannot remember where I puzzled that information together,
> but I do remember it's one of those things that took a long time to find out…

;-)

Interesting, don't we all just love those MS products ?

Sven_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

mmimica
On 25 November 2011 14:04, Sven Van Caekenberghe <[hidden email]> wrote:

On 25 Nov 2011, at 13:47, Johan Brichau wrote:

> It's an Excel thing.
>
> UTF16 is required for a csv file to be opened correctly by excel on both windows and mac platforms
> The csv file also needs to use tabs as separators to make it work correctly.
>
> UTF8 does not work for Excel in that case.
>
> I cannot remember where I puzzled that information together,
> but I do remember it's one of those things that took a long time to find out…

;-)

Interesting, don't we all just love those MS products ?

The funny thing is, 'C' in CSV stands for 'Comma'. 


--
Milan Mimica
http://sparklet.sf.net

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: download content & encoding

Philippe Marschall
In reply to this post by sebastianconcept@gmail.co
2011/11/24 Sebastian Sastre <[hidden email]>:
> done.
> It works.
> Note that mime type is text/csv and it will answer false to #isBinary so it
> needed tweaking there

I filed a bug [1]

 [1] http://code.google.com/p/seaside/issues/detail?id=698

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside