How to get my image (base64) in Google-Cloud-Storage with go script

1 view
Skip to first unread message

hyip script via StackOverflow

unread,
Mar 19, 2015, 11:41:05 AM3/19/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved in json_decode data using Kohana/Cache to Google Cloud Storage (GCS).

Here is the form of stored data of the screenshot image:

stdClass Object
(
    [screenshot] => stdClass Object
        (
            [data] => _9j_4AAQSkZJRgABAQAAAQABAAD_...= // base64 data
            [height] => 240
            [mime_type] => image/jpeg
            [width] => 320
        )

    [ptherdata] => Array
        (
            [..] => ..
            [..] => ..
        )

)

I want to get this image using my customized public url as below that expires in 60 seconds:

http://myapp.appspot.com/image/thumb/mythumb.jpg

I have set in disptach.yaml to send all image request to my go module as below:

- url: "*/images/*"
  module: go

and set the handler go.yaml to proceed the image request as below:

handlers:
- url: /images/thumb/.*
  script: _go_app

- url: /images
  static_dir: images

Using this directive I have got that any /images/ request other than /images/thumb/ serve my images in my static directory and that /images/thumb/ goes to the module.

So left what code I have to use (see ????) in my file named thumb.go as below:

package thumb

import(
    //what to import
    ????
    ????
)

const (
    googleAccessID            = "<serviceAccountEmail>@developer.gserviceaccount.com"
    serviceAccountPEMFilename = "YOUR_SERVICE_ACCOUNT_KEY.pem"
    bucket                    = "YOURBUCKET"
    object                    = "mythumb.jpg"
)

var (
    expiration = time.Now().Add(time.Second * 60) //expire in 60 seconds
)

func init() {
    http.HandleFunc("/images/thumb/", handleThumb)
}

func handleThumb(w http.ResponseWriter, r *http.Request) {
    ctx := cloud.NewContext(appengine.AppID(c), hc)
    ???? //what code to get data from GCS
    ???? //what code to encoce base64 data
    w.Header().Set("Content-Type", "image/jpeg;")    
    fmt.Fprintf(w, "%v\n\n", thumb.jpg)
}

I have tried many examples like this, this and this but could not get one works so far, it was mainly due to lack on what code to be run on the ???? as well the correct library or path to be imported.

I shall thank you for your advise.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/29148777/how-to-get-my-image-base64-in-google-cloud-storage-with-go-script

hyip script via StackOverflow

unread,
Mar 19, 2015, 11:46:05 AM3/19/15
to google-appengin...@googlegroups.com

Using this directive I have got that any /images/ request other than /images/thumb/ serve my images in my static directory and that /images/thumb/mythumb.jpg goes to the module.

So left what code I have to use (see ????) in my file named thumb.go as below:

package thumb

import(
    //what to import
    ????
    ????
)

const (
    googleAccessID            = "<serviceAccountEmail>@developer.gserviceaccount.com
"
    serviceAccountPEMFilename = "YOUR_SERVICE_ACCOUNT_KEY.pem"
    bucket                    = "YOURBUCKET"
    object                    = "mythumb.jpg"
)

var (
    expiration = time.Now().Add(time.Second * 60) //expire in 60 seconds
)

func init() {
    http.HandleFunc("/images/thumb/", handleThumb)
}

func handleThumb(w http.ResponseWriter, r *http.Request) {
    ctx := cloud.NewContext(appengine.AppID(c), hc)
    ???? //what code to get 'mythumb.jpg' from url
    ???? //what code to get stored data in GCS
    ???? //what code to encoce base64 data
    w.Header().Set("Content-Type", "image/jpeg;")    
    fmt.Fprintf(w, "%v\n\n", thumb.jpg)
}

hyip script via StackOverflow

unread,
Mar 19, 2015, 12:06:10 PM3/19/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved in json_decode data using Kohana/Cache to Google Cloud Storage (GCS).

Here is the form of stored data of the screenshot image which is stored in bucket directory named 'cache' and titled 'mythumb.jpg':

hyip script via StackOverflow

unread,
Mar 19, 2015, 12:11:05 PM3/19/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved in json_decode data using Kohana/Cache to Google Cloud Storage (GCS).

Here is the form of stored object containing the screenshot image data (base64) which is stored in bucket directory named 'cache' and titled 'mythumb.jpg':

stdClass Object
(
    [screenshot] => stdClass Object
        (
            [data] => _9j_4AAQSkZJRgABAQAAAQABAAD_...= // base64 data
            [height] => 240
            [mime_type] => image/jpeg
            [width] => 320
        )

    [ptherdata] => Array
        (
            [..] => ..
            [..] => ..
        )

)

I want to get this image using my customized public url as below that expires in 60 seconds:

http://myapp.appspot.com/image/thumb/mythumb.jpg

I have set in disptach.yaml to send all image request to my go module as below:

- url: "*/images/*"
  module: go

and set the handler in go.yaml to proceed the image request as below:

hyip script via StackOverflow

unread,
Mar 19, 2015, 12:26:06 PM3/19/15
to google-appengin...@googlegroups.com

Using this directive I have got that any /images/ request other than /images/thumb/ serve my images in my static directory and that /images/thumb/mythumb.jpg goes to the module application.

So left what code I have to use (see ????) in my application file named thumb.go as below:

package thumb

import(
    //what to import
    ????
    ????
)

const (
    googleAccessID            = "<serviceAccountEmail>@developer.gserviceaccount.com
"
    serviceAccountPEMFilename = "YOUR_SERVICE_ACCOUNT_KEY.pem"
    bucket                    = "YOURBUCKET"
    object                    = "mythumb.jpg"
)

var (
    expiration = time.Now().Add(time.Second * 60) //expire in 60 seconds
)

func init() {
    http.HandleFunc("/images/thumb/", handleThumb)
}

func handleThumb(w http.ResponseWriter, r *http.Request) {
    ctx := cloud.NewContext(appengine.AppID(c), hc)
    ???? //what code to get the string of 'mythumb.jpg' from url
    ???? //what code to get the image stored data from GCS
    ???? //what code to encoce base64 data
    w.Header().Set("Content-Type", "image/jpeg;")    
    fmt.Fprintf(w, "%v", mythumb.jpg)
}

hyip script via StackOverflow

unread,
Mar 19, 2015, 5:41:22 PM3/19/15
to google-appengin...@googlegroups.com

I have taken some codes from many examples like this, this and this but could not get one works so far, it was mainly due to lack on what code to be run on the ???? as well the correct library or path to be imported.

hyip script via StackOverflow

unread,
Mar 19, 2015, 6:01:25 PM3/19/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

Here is the form of stored object containing the screenshot image data (base64) which is stored in bucket directory named cache and titled mythumb.jpg:

stdClass Object
(
    [screenshot] => stdClass Object
        (
            [data] => _9j_4AAQSkZJRgABAQAAAQABAAD_...= // base64 data
            [height] => 240
            [mime_type] => image/jpeg
            [width] => 320
        )

    [otherdata] => Array
        (
            [..] => ..
            [..] => ..
        )

)

I want to get this image using my customized public url as below that expires in 60 seconds:

http://myappId.appspot.com/image/thumb/mythumb.jpg

I have set in disptach.yaml to send all image request to my go module as below:

- url: "*/images/*"
  module: go

and set the handler in go.yaml to proceed the image request as below:

handlers:
- url: /images/thumb/.*
  script: _go_app

- url: /images
  static_dir: images

Using this directive I have got that all /images/ request other than /images/thumb/ serve images from the static directory and that /images/thumb/mythumb.jpg goes to the module application.

So left what code I have to use (see ????) in my application file named thumb.go as below:

package thumb

import(
    //what to import
    ????
    ????
)

const (
    googleAccessID            = "<serviceAccountEmail>@developer.gserviceaccount.com
"
    serviceAccountPEMFilename = "YOUR_SERVICE_ACCOUNT_KEY.pem"
    bucket                    = "myappId.appspot.com"
    object                    = "cache/mythumb.jpg"
)

var (
    expiration = time.Now().Add(time.Second * 60) //expire in 60 seconds
)

func init() {
    http.HandleFunc("/images/thumb/", handleThumb)
}

func handleThumb(w http.ResponseWriter, r *http.Request) {
    ctx := cloud.NewContext(appengine.AppID(c), hc)
    ???? //what code to get the string of 'mythumb.jpg' from url
    ???? //what code to get the image stored data from GCS
    ???? //what code to encoce base64 data
    w.Header().Set("Content-Type", "image/jpeg;")    
    fmt.Fprintf(w, "%v", mythumb.jpg)
}

hyip script via StackOverflow

unread,
Mar 19, 2015, 6:06:25 PM3/19/15
to google-appengin...@googlegroups.com

Using this directive I have got that all /images/ request (other than /images/thumb/ request) serve images from the static directory and that /images/thumb/mythumb.jpg goes to the module application.

hyip script via StackOverflow

unread,
Mar 19, 2015, 6:36:27 PM3/19/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

Here is the form of stored object containing the screenshot image data (base64) which is stored in bucket directory named cache and titled mythumb.jpg:

stdClass Object
(
    [screenshot] => stdClass Object
        (
            [data] => _9j_4AAQSkZJRgABAQAAAQABAAD_...= // base64 data
            [height] => 240
            [mime_type] => image/jpeg
            [width] => 320
        )

    [otherdata] => Array
        (
            [..] => ..
            [..] => ..
        )

)

I want to get this image as public using my customized url as below and that to be expired in 60 seconds:

I have taken some codes from many examples like this, this or this but could not get one works so far, it was mainly due to lack on the correct code to be run on the ???? as well the relevant library or path to be imported.

hyip script via StackOverflow

unread,
Mar 19, 2015, 11:56:56 PM3/19/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

Here is the form of stored object containing the screenshot image data (base64) which is stored in bucket directory named cache and titled mythumb.jpg:

stdClass Object
(
    [screenshot] => stdClass Object
        (
            [data] => _9j_4AAQSkZJRgABAQAAAQABAAD_...= // base64 data
            [height] => 240
            [mime_type] => image/jpeg
            [width] => 320
        )

    [otherdata] => Array
        (
            [..] => ..
            [..] => ..
        )

)

I want to get this image as public using my customized url as below and that to be proceed in go moduleset expires in 60 seconds:

I have taken some codes from many examples like this, this or this but could not get one works so far. It was mainly due to lack on the correct code to be put on the line that I marked by ???? as well the relevant library or path to be imported.

I shall thank you much for your help and advise.

hyip script via StackOverflow

unread,
Mar 20, 2015, 11:59:05 PM3/20/15
to google-appengin...@googlegroups.com
"
    object                    = "cache"
)

var (
    expiration = time.Now().Add(time.Second * 60) //expire in 60 seconds
)

func init() {
    http.HandleFunc("/images/thumb/", handleThumb)
}

func handleThumb(w http.ResponseWriter, r *http.Request) {
    ctx := cloud.NewContext(appengine.AppID(c), hc)
    ???? //what code to get the string of 'mythumb.jpg' from url
    ???? //what code to get the image stored data from GCS
    ???? //what code to encoce base64 data
    w.Header().Set("Content-Type", "image/jpeg;")    
    fmt.Fprintf(w, "%v", mythumb.jpg)
}

I have taken many codes from some examples like this, this or this but could not get one works so far. It was mainly due to lack on the correct code to be put on the line that I marked by ???? as well the relevant library or path to be imported.

hyip script via StackOverflow

unread,
Mar 21, 2015, 12:04:00 AM3/21/15
to google-appengin...@googlegroups.com
"
)

var (
    expiration = time.Now().Add(time.Second * 60) //expire in 60 seconds
)

func init() {
    http.HandleFunc("/images/thumb/", handleThumb)
}

func handleThumb(w http.ResponseWriter, r *http.Request) {
    ctx := cloud.NewContext(appengine.AppID(c), hc)
    ???? //what code to get the string of 'mythumb.jpg' from url
    ???? //what code to get the image stored data from GCS
    ???? //what code to encoce base64 data
    w.Header().Set("Content-Type", "image/jpeg;")    
    fmt.Fprintf(w, "%v", mythumb.jpg)
}

hyip script via StackOverflow

unread,
Mar 21, 2015, 12:29:01 AM3/21/15
to google-appengin...@googlegroups.com

I have taken many codes from some examples like this, this or this but could not get one works so far. I have also tried a sample from this which is almost close to my case but also no luck.

So in generally t was mainly due to lack on what are the correct code to be put on the line that I marked by ???? as well the relevant library or path to be imported.

hyip script via StackOverflow

unread,
Mar 21, 2015, 12:39:01 AM3/21/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

Here is the form of stored object containing the screenshot image data (base64) which is stored in bucket directory named cache and titled mythumb.jpg:

stdClass Object
(
    [screenshot] => stdClass Object
        (
            [data] => _9j_4AAQSkZJRgABAQAAAQABAAD_...= // base64 data
            [height] => 240
            [mime_type] => image/jpeg
            [width] => 320
        )

    [otherdata] => Array
        (
            [..] => ..
            [..] => ..
        )

)

I want to get this image as public using my customized url as below that to be proceed through go module and also I need it to be expired in a certain time because the image content itself is updated regularly:

hyip script via StackOverflow

unread,
Mar 21, 2015, 12:44:05 AM3/21/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

Here is the form of stored object containing the screenshot image data (base64) which is stored in bucket directory named cache and titled mythumb.jpg:

stdClass Object
(
    [screenshot] => stdClass Object
        (
            [data] => _9j_4AAQSkZJRgABAQAAAQABAAD_...= // base64 data
            [height] => 240
            [mime_type] => image/jpeg
            [width] => 320
        )

    [otherdata] => Array
        (
            [..] => ..
            [..] => ..
        )

)

I want to get this image as public using my customized url as below that to be proceed through go module and also I need it to be expired in a certain time because I have managed to update the image content itself regularly:

hyip script via StackOverflow

unread,
Mar 21, 2015, 12:54:06 AM3/21/15
to google-appengin...@googlegroups.com

hyip script via StackOverflow

unread,
Mar 21, 2015, 1:24:04 AM3/21/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

The reason of this method is simply because I found this Kohana model is the most convenient way writing files to GCS, although I am seeking also other way writing files to GCS using Blobstore to serve them but the API Files has been deprecate as documented here.

hyip script via StackOverflow

unread,
Mar 21, 2015, 1:29:05 AM3/21/15
to google-appengin...@googlegroups.com

I have taken many codes from some examples like this, this or this but could not get one works so far. I have also tried a sample from this which is almost close to my case but also found no luck.

hyip script via StackOverflow

unread,
Mar 21, 2015, 1:39:05 AM3/21/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

The reason of this method is simply because I found this Kohana model is the most convenient way writing files to GCS, although I am seeking also other way writing files to GCS using Blobstore to serve them while the Go API Files has been deprecate as documented here.

hyip script via StackOverflow

unread,
Mar 21, 2015, 4:44:13 AM3/21/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

The reason of this method is simply because I found this Kohana model is the most convenient way writing files to GCS, although I am seeking also other way like this to write files to GCS using Blobstore to serve them while the Go API Files has been deprecate as documented here.

So in generally t was mainly due to lack on what are the correct code to be put on the line that I marked by ???? as well the relevant library or path to be imported. I have also checked the GCS permission if something have been missing as described here.

hyip script via StackOverflow

unread,
Mar 21, 2015, 10:25:19 AM3/21/15
to google-appengin...@googlegroups.com

Momer via StackOverflow

unread,
Mar 21, 2015, 4:15:48 PM3/21/15
to google-appengin...@googlegroups.com

From what I've read in your description, it seems that the only relevant parts are the ???? lines in the actual Go code. Let me know if that's not the case.

First ????: "what code to get the string of 'mythumb.jpg' from url"?

From reading the code, you're looking to extract mythumb.jpg from a url like http://localhost/images/thumb/mythumb.jpg. A working example is available at the Writing Web Applications tutorial:

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}

Such that

http://localhost:8080/monkeys

Prints

Hi there, I love monkeys!

Second ????: "what code to get the image stored data from GCS"?

The API method you're probably looking to use is storage.objects.get.

You did link to one of the JSON API Go Examples for Google Cloud Storage, which is a good general reference, but is not related to the problem you're trying to solve. That particular example is put together for Client-side applications (hence the redirectURL = "urn:ietf:wg:oauth:2.0:oob" line). Additionally, this sample uses deprecated/out-of-date oauth2 and storage packages.

One of the cleanest (and non-deprecated) ways to do this for an application which wants to access its own buckets on behalf of itself would be to use the golang/oauth2 and Google APIs Client Library for Go packages.

An example of how to authenticate with JSON Web Token auth with the golang/oauth2 package is available in the repo:

func ExampleJWTConfig() {
    conf := &jwt.Config{
        Email: "x...@developer.com",
        // The contents of your RSA private key or your PEM file
        // that contains a private key.
        // If you have a p12 file instead, you
        // can use `openssl` to export the private key into a pem file.
        //
        //    $ openssl pkcs12 -in key.p12 -out key.pem -nodes
        //
        // It only supports PEM containers with no passphrase.
        PrivateKey: []byte("-----BEGIN RSA PRIVATE KEY-----..."),
        Subject:    "us...@example.com",
        TokenURL:   "https://provider.com/o/oauth2/token",
    }
    // Initiate an http.Client, the following GET request will be
    // authorized and authenticated on the behalf of us...@example.com.
    client := conf.Client(oauth2.NoContext)
    client.Get("...")
}

Next, instead of using the oauth2 client directly, use that client with the Google APIs Client Library for Go mentioned earlier:

// Notice the similarity to the out-of-date [JSON API Go Examples](https://cloud.google.com/storage/docs/json_api/v1/json-api-go-samples)?
service, err := storage.New(client)
if err != nil {
    fatalf(service, "Failed to create service %v", err)
}

In your handler, you'll want to go out and get the related object using func ObjectsService.Get. Assuming that you know the name of the object and bucket, that is.

Straight from the previous example, you can use code similar to what's below to retrieve the download link:

if res, err := service.Objects.Get(bucketName, objectName).Do(); err == nil {
    fmt.Printf("The media download link for %v/%v is %v.\n\n", bucketName, res.Name, res.MediaLink)
} else {
    fatalf(service, "Failed to get %s/%s: %s.", bucketName, objectName, err)
}

Then, fetch the file, or do whatever you want with it.

Third ????: "what code to encoce base64 data"?

Pretty simple with the encoding/base64 package. SO simple, that they've included an example:

package main

import (
    "encoding/base64"
    "fmt"
)

func main() {
    data := []byte("any + old & data")
    str := base64.StdEncoding.EncodeToString(data)
    fmt.Println(str)
}

Hope that helps.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/29148777/how-to-get-my-image-base64-in-google-cloud-storage-with-go-script/29187533#29187533

Momer via StackOverflow

unread,
Mar 21, 2015, 4:20:44 PM3/21/15
to google-appengin...@googlegroups.com
service, err := storage.New(client)
if err != nil {
    fatalf(service, "Failed to create service %v", err)
}

Notice the similarity to the out-of-date JSON API Go Examples?

hyip script via StackOverflow

unread,
Mar 21, 2015, 5:05:50 PM3/21/15
to google-appengin...@googlegroups.com

Momer via StackOverflow

unread,
Mar 22, 2015, 2:48:35 PM3/22/15
to google-appengin...@googlegroups.com

Then, fetch the file, or do whatever you want with it. Full example:

import (
    "golang.org/x/oauth2"
    "golang.org/x/oauth2/jwt"
    "google.golang.org/api/storage/v1"
    "fmt"
)

...

func main() {
    conf := &jwt.Config{
        Email: "x...@developer.com",
        PrivateKey: []byte("-----BEGIN RSA PRIVATE KEY-----..."),
        Subject:    "us...@example.com",
        TokenURL:   "https://provider.com/o/oauth2/token",
     }

    client := conf.Client(oauth2.NoContext)

    service, err := storage.New(client)
    if err != nil {
        fatalf(service, "Failed to create service %v", err)
    }

    if res, err := service.Objects.Get(bucketName, objectName).Do(); err == nil {
        fmt.Printf("The media download link for %v/%v is %v.\n\n", bucketName, res.Name, res.MediaLink)
    } else {
        fatalf(service, "Failed to get %s/%s: %s.", bucketName, objectName, err)
    }

    // Go fetch the file, etc.
}

Third ????: "what code to encoce base64 data"?

Pretty simple with the encoding/base64 package. SO simple, that they've included an example:

package main

import (
    "encoding/base64"
    "fmt"
)

func main() {
    data := []byte("any + old & data")
    str := base64.StdEncoding.EncodeToString(data)
    fmt.Println(str)
}

Hope that helps.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/29148777/how-to-get-my-image-base64-in-google-cloud-storage-with-go-script/29187533#29187533

hyip script via StackOverflow

unread,
Mar 22, 2015, 3:18:42 PM3/22/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

The reason of this method is simply because I found this Kohana model is the most convenient way writing files to GCS, although I am seeking also other way like this to write files to GCS using Blobstore to serve them while the Go API Files has been deprecate as documented here.

Here is the form of stored object containing the screenshot image data (base64) which is saved as public in default application bucket with object name images/thumb/mythumb.jpg:

hyip script via StackOverflow

unread,
Mar 22, 2015, 3:28:39 PM3/22/15
to google-appengin...@googlegroups.com
package main

import(
    //what to import
    ????
    ????
)

const (
    googleAccessID            = "<serviceAccountEmail>@developer.gserviceaccount.com"
    serviceAccountPEMFilename = "YOUR_SERVICE_ACCOUNT_KEY.pem"
    bucket                    = "myappId.appspot.com"
)

var (
    expiration = time.Now().Add(time.Second * 60) //expire in 60 seconds
)

func init() {
    http.HandleFunc("/images/thumb/", main)
}

func main(w http.ResponseWriter, r *http.Request) {
    ctx := cloud.NewContext(appengine.AppID(c), hc)
    ???? //what code to get the string of 'mythumb.jpg' from url
    ???? //what code to get the image stored data from GCS
    ???? //what code to encoce base64 data
    w.Header().Set("Content-Type", "image/jpeg;")    
    fmt.Fprintf(w, "%v", mythumb.jpg)
}

hyip script via StackOverflow

unread,
Mar 22, 2015, 4:59:01 PM3/22/15
to google-appengin...@googlegroups.com
package thumb

import(
    //what to import
    ????
    ????
)

const (
    googleAccessID            = "<serviceAccountEmail>@developer.gserviceaccount.com"
    serviceAccountPEMFilename = "YOUR_SERVICE_ACCOUNT_KEY.pem"
    bucket                    = "myappId.appspot.com"
)

var (
    expiration = time.Now().Add(time.Second * 60) //expire in 60 seconds
)

func init() {
    http.HandleFunc("/images/thumb/", handleThumb)
}

func handleThumb(w http.ResponseWriter, r *http.Request) {
    ctx := cloud.NewContext(appengine.AppID(c), hc)
    ???? //what code to get the string of 'mythumb.jpg' from url
    ???? //what code to get the image stored data from GCS
    ???? //what code to encoce base64 data
    w.Header().Set("Content-Type", "image/jpeg;")    
    fmt.Fprintf(w, "%v", mythumb.jpg)
}

hyip script via StackOverflow

unread,
Mar 24, 2015, 3:32:55 PM3/24/15
to google-appengin...@googlegroups.com

So in generally t was mainly due to lack on what are the correct code to be put on the line that I marked by ???? as well the relevant library or path to be imported. I have also checked the GCS permission if something have been missing as described here and here.

hyip script via StackOverflow

unread,
Mar 24, 2015, 5:13:32 PM3/24/15
to google-appengin...@googlegroups.com

I have been looking for an example GAE script in go to get my image that I got from the resulted screenshot of PageSpeed Insights and saved it as json_decode object using Kohana/Cache to Google Cloud Storage (GCS).

The reason of this method is simply because I found this Kohana model is the most convenient way writing files to GCS, although I am seeking also other way like this to write files to GCS using Blobstore to serve them while the Go API Files has been deprecate as documented here.

Here is the form of stored object containing the screenshot image data (base64) which is saved as public in default application bucket with object name images/thumb/mythumb.jpg:

stdClass Object
(
    [screenshot] => stdClass Object
        (
            [data] => _9j_4AAQSkZJRgABAQAAAQABAAD_...= // base64 data
            [height] => 240
            [mime_type] => image/jpeg
            [width] => 320
        )

    [otherdata] => Array
        (
            [..] => ..
            [..] => ..
        )

)

I want to get this image that set as public using my customized url as below that to be proceed through go module and also I need it to be expired in a certain time because I have managed to update the image content itself regularly:

Reply all
Reply to author
Forward
0 new messages