Esempio n. 1
0
// 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
}
Esempio n. 2
0
func (self *UpResuPut) doTestRSGet() (msg string, err error) {
	var ret rss.GetRet

	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	rsservice, err := rss.NewRS(&self.Conf, dt)
	if err != nil {
		return
	}
	begin := time.Now()
	ret, code, err := rsservice.Get(self.EntryURI, "", "", 3600)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLog("UP    "+self.Env.Id+"_"+self.Name+"_doTestRsGet", begin, end, duration)

	if err != nil || code != 200 {
		return
	}
	self.Url = ret.URL
	return
}
Esempio n. 3
0
func (self *Fileop) doTestGetImgDownloadUrl() (url string, err error) {
	var conf service.Config
	// load config
	self.buildConfig(&conf)
	self.Conf = conf
	fmt.Println("conf : ", conf)
	//rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
	//entry := fp.BucketName + ":" + fp.ImageFile + "_" + strconv.FormatInt(rnd.Int63(), 10)
	entry := self.BucketName + ":fixed_entry_not_delete"
	/*policy := &gup.AuthPolicy{
		Scope:    entry,
		Deadline: 3600,
		Customer: "1234",
	}
	policy.Deadline += uint32(time.Now().Unix())*/
	//token := gup.MakeAuthTokenString(fp.AccessKey, fp.SecretKey, policy)

	/*_, code, err := rss.Upload(entry, fp.ImageFile, "", "", "", token)

	if err != nil || code != 200 {
		return
	}*/

	dt := da.NewTransport(self.Conf.AccessKey, self.Conf.SecretKey, nil)
	conn, err := rs.NewRS(&self.Conf, dt)
	if err != nil {
		return
	}

	begin := time.Now()
	getRet, code, err := conn.Get(entry, "", "", 3600)

	if err != nil || code != 200 {
		return
	}
	end := time.Now()
	self.DoLog2("doTestImgUrl", begin, end, end.Sub(begin))

	url = getRet.URL
	return
}
Esempio n. 4
0
func NewRS(c service.Config) (*rss.RSService, error) {
	dt := digest.NewTransport(c.AccessKey, c.SecretKey, nil)
	return rss.NewRS(&c, dt)
}