Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
ad61be03
Commit
ad61be03
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
fixes #1908 by switching the csv download over to using an http POST request.
parent
25f1c08f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/query_builder/QueryVisualization.jsx
+21
-4
21 additions, 4 deletions
frontend/src/query_builder/QueryVisualization.jsx
src/metabase/api/dataset.clj
+21
-0
21 additions, 0 deletions
src/metabase/api/dataset.clj
with
42 additions
and
4 deletions
frontend/src/query_builder/QueryVisualization.jsx
+
21
−
4
View file @
ad61be03
...
...
@@ -132,10 +132,17 @@ export default class QueryVisualization extends Component {
}
}
onDownloadCSV
()
{
const
form
=
this
.
_downloadCsvForm
.
getDOMNode
();
form
.
query
.
value
=
JSON
.
stringify
(
this
.
props
.
card
.
dataset_query
);
form
.
submit
();
}
renderDownloadButton
()
{
const
{
downloadLink
}
=
this
.
props
;
// NOTE: we expect our component provider set this to something falsey if download not available
// TODO: it's likely the downloading won't work with large query expressions on the Mac App
if
(
downloadLink
)
{
const
{
result
}
=
this
.
props
;
...
...
@@ -148,7 +155,14 @@ export default class QueryVisualization extends Component {
this
.
refs
.
downloadModal
.
toggle
()
}
}
>
Download CSV
</
button
>);
}
else
{
downloadButton
=
(<
a
className
=
"Button Button--primary"
href
=
{
downloadLink
}
target
=
"_blank"
onClick
=
{
()
=>
this
.
refs
.
downloadModal
.
toggle
()
}
>
Download CSV
</
a
>);
downloadButton
=
(
<
form
ref
=
{
(
c
)
=>
this
.
_downloadCsvForm
=
c
}
method
=
"POST"
action
=
"/api/dataset/csv"
>
<
input
type
=
"hidden"
name
=
"query"
value
=
""
/>
<
a
className
=
"Button Button--primary"
onClick
=
{
()
=>
{
this
.
onDownloadCSV
();
this
.
refs
.
downloadModal
.
toggle
();}
}
>
Download CSV
</
a
>
</
form
>
);
}
return
(
...
...
@@ -183,9 +197,12 @@ export default class QueryVisualization extends Component {
);
}
else
{
return
(
<
a
className
=
"mx1"
href
=
{
downloadLink
}
title
=
"Download this data"
target
=
"_blank"
>
<
Icon
name
=
'download'
width
=
"16px"
height
=
"16px"
/>
</
a
>
<
form
ref
=
{
(
c
)
=>
this
.
_downloadCsvForm
=
c
}
method
=
"POST"
action
=
"/api/dataset/csv"
>
<
input
type
=
"hidden"
name
=
"query"
value
=
""
/>
<
a
className
=
"mx1"
title
=
"Download this data"
onClick
=
{
()
=>
this
.
onDownloadCSV
()
}
>
<
Icon
name
=
'download'
width
=
"16px"
height
=
"16px"
/>
</
a
>
</
form
>
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/metabase/api/dataset.clj
+
21
−
0
View file @
ad61be03
...
...
@@ -45,4 +45,25 @@
{
:status
500
:body
(
:error
response
)})))
(
defendpoint
POST
"/csv"
"Execute an MQL query and download the result data as a CSV file."
[
query
]
{
query
[
Required
String->Dict
]}
(
clojure.pprint/pprint
query
)
(
read-check
Database
(
:database
query
))
(
let
[{{
:keys
[
columns
rows
]}
:data
:keys
[
status
]
:as
response
}
(
driver/dataset-query
query
{
:executed_by
*current-user-id*
})
columns
(
map
name
columns
)]
; turn keywords into strings, otherwise we get colons in our output
(
if
(
=
status
:completed
)
;; successful query, send CSV file
{
:status
200
:body
(
with-out-str
(
csv/write-csv
*out*
(
into
[
columns
]
rows
)))
:headers
{
"Content-Type"
"text/csv"
"Content-Disposition"
(
str
"attachment; filename=\"query_result_"
(
u/date->iso-8601
)
".csv\""
)}}
;; failed query, send error message
{
:status
500
:body
(
:error
response
)})))
(
define-routes
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment