示例#1
0
文件: processor.go 项目: plimble/ivy
func (p *processor) Process(path string, opt *bimg.Options) ([]byte, bimg.ImageType, error) {
	data, err := p.source.Get(path)
	if err != nil {
		return nil, 0, err
	}

	result, err := bimg.NewImage(data).Process(*opt)
	imgType := bimg.DetermineImageType(result)

	return result, imgType, errors.InternalServerErrorErr(err)
}
示例#2
0
文件: s3.go 项目: plimble/ivy
func (s *S3) Get(path string) ([]byte, error) {
	b := aws.NewWriteAtBuffer(nil)
	_, err := s.s3.Download(b, &s3.GetObjectInput{
		Bucket: aws.String(s.bucket),
		Key:    aws.String(path),
	})

	if err != nil {
		cerr := err.(awserr.Error)
		if cerr.Code() == "NoSuchKey" {
			return nil, errors.NotFound("not found")
		}

		return nil, errors.InternalServerErrorErr(err)
	}

	return b.Bytes(), nil
}