<commit_before>package gae

import (
	"code.google.com/p/go.net/context"
	"encoding/json"
	"fmt"
	"github.com/golang/oauth2"
	"github.com/golang/oauth2/google"
	"github.com/snakehopper/gcloud-golang/storage"
	"google.golang.org/appengine"
	"google.golang.org/appengine/blobstore"
	"google.golang.org/appengine/file"
	"google.golang.org/appengine/log"
	"google.golang.org/cloud"
	"io/ioutil"
	"mime/multipart"
	"strings"
)

type GStorage struct {
	ctx context.Context
	// bucket is the Google Cloud Storage bucket name used for the GStorage.
	bucket string
	// failed indicates that one or more of the GStorage steps failed.
	failed bool
}

func NewGStorage(c context.Context) (*GStorage, error) {
	bucketName, err := file.DefaultBucketName(c)
	if err != nil {
		log.Errorf(c, "failed to get default GCS bucket name: %v", err)
		return nil, err
	}

	client, err := google.DefaultClient(oauth2.NoContext, storage.ScopeFullControl)
	if err != nil {
		return nil, err
	}

	ctx := cloud.NewContext(appengine.AppID(c), client)

	gs := &GStorage{
		ctx:    ctx,
		bucket: bucketName,
	}
	return gs, nil
}

func (gs *GStorage) CreateImageFile(fileName string, img multipart.File, ct string) error {
	wc := storage.NewWriter(gs.ctx, gs.bucket, fileName, &storage.Object{
		ContentType: ct,
		//Metadata:    map[string]string{},
	})

	b, err := ioutil.ReadAll(img)<commit_msg>Fix storage operation context to use GAE one<commit_after>package gae

import (
	"code.google.com/p/go.net/context"
	"encoding/json"
	"fmt"
	"github.com/golang/oauth2"
	"github.com/golang/oauth2/google"
	"github.com/snakehopper/gcloud-golang/storage"
	"google.golang.org/appengine"
	"google.golang.org/appengine/blobstore"
	"google.golang.org/appengine/file"
	"google.golang.org/appengine/log"
	"google.golang.org/cloud"
	"io/ioutil"
	"mime/multipart"
	"strings"
)

type GStorage struct {
	ctx context.Context
	// bucket is the Google Cloud Storage bucket name used for the GStorage.
	bucket string
	// failed indicates that one or more of the GStorage steps failed.
	failed bool
}

func NewGStorage(c context.Context) (*GStorage, error) {
	bucketName, err := file.DefaultBucketName(c)
	if err != nil {
		log.Errorf(c, "failed to get default GCS bucket name: %v", err)
		return nil, err
	}

	client, err := google.DefaultClient(oauth2.NoContext, storage.ScopeFullControl)
	if err != nil {
		return nil, err
	}

	ctx := cloud.WithContext(c, appengine.AppID(c), client)

	gs := &GStorage{
		ctx:    ctx,
		bucket: bucketName,
	}
	return gs, nil
}

func (gs *GStorage) CreateImageFile(fileName string, img multipart.File, ct string) error {
	wc := storage.NewWriter(gs.ctx, gs.bucket, fileName, &storage.Object{
		ContentType: ct,
		//Metadata:    map[string]string{},
	})

	b, err := ioutil.ReadAll(img)
{'fraction_non_alphanumeric': 0.1319118178532707, 'fraction_numerical': 0.0021684134441633538, 'mean_word_length': 4.212806026365349, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2919678', 'n_tokens_mistral': 1055, 'n_tokens_neox': 997, 'n_words': 241}