// upload the file and get the download url func (self *PutFile) doTestPutFile() (url, msg string, err error) { entry := self.BucketName + ":" + self.Key authPolicy := &uptoken.AuthPolicy{ Scope: entry, Deadline: 3600, } authPolicy.Deadline += uint32(time.Now().Unix()) token := uptoken.MakeAuthTokenString(self.Env.AccessKey, self.Env.SecretKey, authPolicy) // in fact, upload should be a part of Up not Rs begin := time.Now() _, code, err := self.Conn.Upload(entry, self.DataFile, "", "", "", token) end := time.Now() duration := end.Sub(begin) msg = util.GenLogEx("UP "+self.Env.Id+"_"+self.Name+"_doTestPutFile", begin, end, duration) if err != nil || code != 200 { return } getRet, code, err := self.Conn.Get(entry, "", "", 3600) if err != nil || code != 200 { return } url = getRet.URL // check shal return }
// upload the file and get the download url func (self *FopImgInfo) doTestGetImgUrl() (url string, err error) { entry := self.BucketName + ":" + self.Key dt := da.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil) rsservice, err := rs.New(self.Env.Hosts, self.Env.Ips, dt) if err != nil { return } authPolicy := &uptoken.AuthPolicy{ Scope: entry, Deadline: 3600, } authPolicy.Deadline += uint32(time.Now().Unix()) token := uptoken.MakeAuthTokenString(self.Env.AccessKey, self.Env.SecretKey, authPolicy) _, code, err := rsservice.Upload(entry, self.SrcImg, "", "", "", token) if err != nil || code != 200 { return } getRet, code, err := rsservice.Get(entry, "", "", 3600) if err != nil || code != 200 { return } url = getRet.URL return }
// upload the file and get the download url func (self *FopImgOp) doTestGetImgUrl() (url string, err error) { entry := self.BucketName + ":" + self.Key dt := da.NewTransport(self.Conf.AccessKey, self.Conf.SecretKey, nil) rsservice, err := rs.NewRS(&self.Conf, dt) if err != nil { return } authPolicy := &uptoken.AuthPolicy{ Scope: entry, Deadline: 3600, } authPolicy.Deadline += uint32(time.Now().Unix()) token := uptoken.MakeAuthTokenString(self.Conf.AccessKey, self.Conf.SecretKey, authPolicy) _, code, err := rsservice.Upload(entry, self.SrcImg, "", "", "", token) if err != nil || code != 200 { return } /*f, err := os.Open(self.SrcImg) if err != nil { return } defer f.Close() fi, err := f.Stat() if err != nil { return } _, code, err := rsservice.Put(entry, "", f, fi.Size()) fmt.Println("rs.Put ", code, err ) if err != nil || code != 200 { return }*/ getRet, code, err := rsservice.Get(entry, "", "", 3600) if err != nil || code != 200 { return } url = getRet.URL return }
func doTestInit(t *testing.T) { var ( c Config ) // load config b, err := ioutil.ReadFile("qbox.conf") if err != nil { t.Fatal(err) } if err = json.Unmarshal(b, &c); err != nil { t.Fatal(err) } // create auth transport layer, uptoken and digest auth := &uptoken.AuthPolicy{} token := uptoken.MakeAuthTokenString(c.AccessKey, c.SecretKey, auth) // uptoken transport ut := uptoken.NewTransport(token, nil) // digest transport dt := digest.NewTransport(c.AccessKey, c.SecretKey, nil) if eus, err = eu.New(&c, dt); err != nil { t.Fatal(err) } if pubs, err = pub.New(&c, dt); err != nil { t.Fatal(err) } if rss, err = rs.New(&c, dt); err != nil { t.Fatal(err) } if ucs, err = uc.New(&c, dt); err != nil { t.Fatal(err) } if ups, err = up.New(&c, ut); err != nil { t.Fatal(err) } if ims, err = image.New(&c, dt); err != nil { t.Fatal(err) } }