Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Import data from Google Cloud Storage, save locally, produce png, and save to Google Cloud Storage.
using Gadfly
using HTTPClient.HTTPC
using JSON
using RDatasets
token_url = "http://metadata/computeMetadata/v1/instance/service-accounts/default/token"
request = HTTPC.get(token_url, RequestOptions(headers=[("X-Google-Metadata-Request", "True")]))
access_token = JSON.parse(bytestring(request.body))["access_token"]
bucket_name = <bucket_name>
file_name = <data_file_name>
project_number = <project_number>
request_url = string("", bucket_name, "/o/", file_name, "?alt=media")
request = HTTPC.get(request_url, RequestOptions(headers=[("Authorization", string("OAuth ", access_token)),
("x-goog-api-version", "2"),
("x-goog-project-id", project_number)]))
fp = open(file_name, "w")
write(fp, takebuf_string(request.body))
wine_data = readtable(file_name)
alcohol_vs_magnesium = plot(wine_data, x="Alcohol", y="Magnesium", Geom.point)
png_name = "alcohol_vs_magnesium.png"
draw(PNG(png_name, 6inch, 3inch),alcohol_vs_magnesium)
file_len = strip(readall(`stat -c %s $png_name`))
request_url = string("", bucket_name, "/o?uploadType=media&name=",png_name)
options = RequestOptions(headers=[("Authorization", string("OAuth ", access_token)),("Content-Type","image/png"),("Content-Length", string(file_len))])
request =, (:file, png_name), options)
println("Check your bucket!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.