Ejemplo n.º 1
0
Archivo: alioss.go Proyecto: nowa/OCSS
func (s *Service) HeadObject(o *fs.Object) (code int, err error) {
	url := s.Host + o.EntryURI
	resp, err := s.Conn.Post("HEAD", url)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	code = resp.StatusCode
	if code/100 == 2 {
		o.Type = resp.Header.Get("Content-Type")
		o.ETag = resp.Header.Get("ETag")
		o.Size, err = strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
		if err != nil {
			o.Size = 0
		}
		o.Mtime = resp.Header.Get("Last-Modified")
		if o.Meta == nil {
			o.Meta = make(map[string]string)
		}
		for k, v := range resp.Header {
			prefix := "x-oss-meta-"
			if strings.HasPrefix(k, prefix) == false {
				continue
			}
			o.Meta[strings.TrimLeft(k, prefix)] = v[0]
		}
	}
	return
}
Ejemplo n.º 2
0
Archivo: alioss.go Proyecto: nowa/OCSS
func (s *Service) GetObject(o *fs.Object) (code int, err error) {
	url := s.Host + o.EntryURI
	resp, err := s.Conn.Post("GET", url)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	code = resp.StatusCode
	if code/100 == 2 && resp.ContentLength != 0 {
		o.Size, err = io.Copy(o.Body, resp.Body)
		if err != nil {
			return
		}
		o.ETag = resp.Header.Get("ETag")
		o.Type = resp.Header.Get("Content-Type")
		o.Mtime = resp.Header.Get("Last-Modified")
	}
	return
}
Ejemplo n.º 3
0
Archivo: alioss.go Proyecto: nowa/OCSS
func (s *Service) PutObject(o *fs.Object) (code int, err error) {
	var addi map[string]interface{}

	if o.Type == "" {
		o.Type = "application/octet-stream"
	}
	url := s.Host + o.EntryURI
	for k, v := range o.Meta {
		addi["x-oss-meta-"+k] = v
	}
	resp, err := s.Conn.Post("PUT", url, o.Type, o.Body, o.Size, addi)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	code = resp.StatusCode
	if code/100 == 2 {
		o.ETag = resp.Header.Get("ETag")
	}
	return
}