CartoDB / CartoDB-SQL-API

CartoDB SQL API
BSD 3-Clause "New" or "Revised" License
63 stars 65 forks source link

Exporting tables of non-org users always result in public.ext name #271

Open rafatower opened 8 years ago

rafatower commented 8 years ago

How to reproduce:

Expected: the name of the downloaded file is set to whosonfirst_region.csv or sth related to the exported table.

Actual: the downloaded file is set to public.csv.

The thing is that the Content-Disposition header sets the filename to public.csv:

$ curl -vv -X HEAD "https://observatory.cartodb.com/api/v2/sql?filename="public.whosonfirst_region"&q=SELECT+*+FROM+(select+*+from+public.whosonfirst_region)+as+subq+&format=csv&bounds=&api_key=&skipfields=the_geom_webmercator"
...
> HEAD /api/v2/sql?filename=public.whosonfirst_region&q=SELECT+*+FROM+(select+*+from+public.whosonfirst_region)+as+subq+&format=csv&bounds=&api_key=&skipfields=the_geom_webmercator HTTP/1.1
> User-Agent: curl/7.35.0
> Host: observatory.cartodb.com
> Accept: */*
> 
< HTTP/1.1 200 OK
* Server openresty is not blacklisted
< Server: openresty
< Date: Thu, 18 Feb 2016 12:11:26 GMT
< Content-Type: text/csv; charset=utf-8; header=present
< Content-Length: 63677977
< Connection: keep-alive
< Vary: Accept-Encoding
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: X-Requested-With, X-Prototype-Version, X-CSRF-Token
< Content-Disposition: attachment; filename=public.csv; modification-date="Thu, 18 Feb 2016 12:01:07 GMT";
< Cache-Control: no-cache,max-age=31536000,must-revalidate,public
< Last-Modified: Mon, 01 Feb 2016 22:13:32 GMT
< X-SQLAPI-Profiler: {"queryExplain":5,"generate":493,"beforeSink":1,"total":499}
< X-Varnish: 1771113958 1771043295
< Age: 619
< X-Cache: HIT

Related to https://github.com/CartoDB/cartodb/issues/6609

iriberri commented 8 years ago

I rechecked the HEAD request to the URL and saw that the underscore is coming directly with the tablename in the Content-Disposition:

image

It seems that some browsers or tools (like Postman or Typhoeus) are doing these things. I see that if in the filename parameter of the URL you get rid of points and quotes, the name of the downloaded file is just "public", but the quotes are giving me _public or _public_ in Chrome, Typhoeus and Postman.

rochoa commented 8 years ago

We can improve the name formatting for filenames but providing a different filename param with the desired name should do the trick, and that's something the client is controlling on this case.