mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Direct file upload on image service (#264)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"image"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
@@ -49,17 +50,20 @@ func (e *Image) Upload(ctx context.Context, req *img.UploadRequest, rsp *img.Upl
|
||||
if !ok {
|
||||
return merrors.Unauthorized("image.Upload", "Not authorized")
|
||||
}
|
||||
var srcImage image.Image
|
||||
var imageBytes *bytes.Buffer
|
||||
var err error
|
||||
var ext string
|
||||
|
||||
if len(req.Base64) > 0 {
|
||||
srcImage, ext, err = base64ToImage(req.Base64)
|
||||
if len(req.File) > 0 {
|
||||
imageBytes = bytes.NewBuffer(req.File)
|
||||
|
||||
} else if len(req.Base64) > 0 {
|
||||
b, _, err := base64ToImage(req.Base64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
imageBytes = bytes.NewBuffer(b)
|
||||
} else if len(req.Url) > 0 {
|
||||
ur, err := url.Parse(req.Url)
|
||||
_, err := url.Parse(req.Url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -68,36 +72,16 @@ func (e *Image) Upload(ctx context.Context, req *img.UploadRequest, rsp *img.Upl
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
switch {
|
||||
case strings.HasSuffix(ur.Path, ".png"):
|
||||
srcImage, err = png.Decode(response.Body)
|
||||
case strings.HasSuffix(ur.Path, ".jpg") || strings.HasSuffix(ur.Path, ".jpeg"):
|
||||
srcImage, err = jpeg.Decode(response.Body)
|
||||
}
|
||||
b, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
imageBytes = bytes.NewBuffer(b)
|
||||
} else {
|
||||
return errors.New("base64 or url param is required")
|
||||
return merrors.BadRequest("image.Upload", "file, base64 or url param is required")
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
switch {
|
||||
case strings.HasSuffix(req.Name, ".png") || ext == "png":
|
||||
err = png.Encode(buf, srcImage)
|
||||
case strings.HasSuffix(req.Name, ".jpg") || strings.HasSuffix(req.Url, ".jpeg") || ext == "jpg":
|
||||
err = jpeg.Encode(buf, srcImage, nil)
|
||||
default:
|
||||
return errors.New("could not determine extension")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = store.DefaultBlobStore.Write(fmt.Sprintf("%v/%v/%v", pathPrefix, tenantID, req.Name), buf, store.BlobPublic(true))
|
||||
err = store.DefaultBlobStore.Write(fmt.Sprintf("%v/%v/%v", pathPrefix, tenantID, req.Name), imageBytes, store.BlobPublic(true))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -105,32 +89,25 @@ func (e *Image) Upload(ctx context.Context, req *img.UploadRequest, rsp *img.Upl
|
||||
return nil
|
||||
}
|
||||
|
||||
func base64ToImage(b64 string) (image.Image, string, error) {
|
||||
var srcImage image.Image
|
||||
func base64ToImage(b64 string) ([]byte, string, error) {
|
||||
ext := ""
|
||||
|
||||
parts := strings.Split(b64, ",")
|
||||
if len(parts) != 2 {
|
||||
return srcImage, "", merrors.BadRequest("image", "Incorrect format for base64 image, expected <encoding prefix>,<image data>")
|
||||
return nil, "", merrors.BadRequest("image", "Incorrect format for base64 image, expected <encoding prefix>,<image data>")
|
||||
}
|
||||
prefix := parts[0]
|
||||
b64 = strings.TrimSpace(parts[1])
|
||||
res, err := base64.StdEncoding.DecodeString(b64)
|
||||
if err != nil {
|
||||
return srcImage, ext, err
|
||||
}
|
||||
|
||||
switch prefix {
|
||||
case "data:image/png;base64":
|
||||
srcImage, err = png.Decode(bytes.NewReader(res))
|
||||
ext = "png"
|
||||
case "data:image/jpg;base64", "data:image/jpeg;base64":
|
||||
srcImage, err = jpeg.Decode(bytes.NewReader(res))
|
||||
ext = "jpg"
|
||||
default:
|
||||
return srcImage, ext, errors.New("unrecognized base64 prefix: " + prefix)
|
||||
return nil, ext, errors.New("unrecognized base64 prefix: " + prefix)
|
||||
}
|
||||
return srcImage, ext, err
|
||||
b, err := base64.StdEncoding.DecodeString(b64)
|
||||
return b, ext, err
|
||||
}
|
||||
|
||||
func (e *Image) Resize(ctx context.Context, req *img.ResizeRequest, rsp *img.ResizeResponse) error {
|
||||
@@ -138,12 +115,14 @@ func (e *Image) Resize(ctx context.Context, req *img.ResizeRequest, rsp *img.Res
|
||||
if !ok {
|
||||
return merrors.Unauthorized("image.Resize", "Not authorized")
|
||||
}
|
||||
var srcImage image.Image
|
||||
var imageBytes []byte
|
||||
var err error
|
||||
var ext string
|
||||
|
||||
if len(req.Base64) > 0 {
|
||||
srcImage, ext, err = base64ToImage(req.Base64)
|
||||
if len(req.File) > 0 {
|
||||
imageBytes = req.File
|
||||
} else if len(req.Base64) > 0 {
|
||||
imageBytes, ext, err = base64ToImage(req.Base64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -157,20 +136,25 @@ func (e *Image) Resize(ctx context.Context, req *img.ResizeRequest, rsp *img.Res
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
switch {
|
||||
case strings.HasSuffix(ur.Path, ".png"):
|
||||
srcImage, err = png.Decode(response.Body)
|
||||
case strings.HasSuffix(ur.Path, ".jpg") || strings.HasSuffix(ur.Path, ".jpeg"):
|
||||
srcImage, err = jpeg.Decode(response.Body)
|
||||
}
|
||||
imageBytes, err = ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch {
|
||||
case strings.HasSuffix(ur.Path, ".png"):
|
||||
ext = "png"
|
||||
case strings.HasSuffix(ur.Path, ".jpg") || strings.HasSuffix(ur.Path, ".jpeg"):
|
||||
ext = "jpg"
|
||||
}
|
||||
} else {
|
||||
return errors.New("base64 or url param is required")
|
||||
}
|
||||
|
||||
srcImage, _, err := image.Decode(bytes.NewReader(imageBytes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resultImage := imaging.Resize(srcImage, int(req.Width), int(req.Height), imaging.Lanczos)
|
||||
if req.CropOptions != nil {
|
||||
anchor := imaging.Center
|
||||
@@ -230,14 +214,17 @@ func (e *Image) Convert(ctx context.Context, req *img.ConvertRequest, rsp *img.C
|
||||
return merrors.Unauthorized("image.Convert", "Not authorized")
|
||||
}
|
||||
var srcImage image.Image
|
||||
var imageBytes []byte
|
||||
var err error
|
||||
if len(req.Base64) > 0 {
|
||||
srcImage, _, err = base64ToImage(req.Base64)
|
||||
if len(req.File) > 0 {
|
||||
imageBytes = req.File
|
||||
} else if len(req.Base64) > 0 {
|
||||
imageBytes, _, err = base64ToImage(req.Base64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
ur, err := url.Parse(req.Url)
|
||||
} else if len(req.Url) > 0 {
|
||||
_, err := url.Parse(req.Url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -247,16 +234,17 @@ func (e *Image) Convert(ctx context.Context, req *img.ConvertRequest, rsp *img.C
|
||||
return err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
switch {
|
||||
case strings.HasSuffix(ur.Path, ".png"):
|
||||
srcImage, err = png.Decode(response.Body)
|
||||
case strings.HasSuffix(ur.Path, ".jpg") || strings.HasSuffix(ur.Path, ".jpeg"):
|
||||
srcImage, err = jpeg.Decode(response.Body)
|
||||
}
|
||||
imageBytes, err = ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return merrors.BadRequest("image.Convert", "Must pass either base64, url, or file param")
|
||||
}
|
||||
|
||||
srcImage, _, err = image.Decode(bytes.NewReader(imageBytes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
@@ -22,6 +22,8 @@ const (
|
||||
|
||||
// Upload an image by either sending a base64 encoded image to this endpoint or a URL.
|
||||
// To resize an image before uploading, see the Resize endpoint.
|
||||
// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json
|
||||
// with each parameter as a form field.
|
||||
type UploadRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -33,6 +35,8 @@ type UploadRequest struct {
|
||||
Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"`
|
||||
// Output name of the image including extension, ie. "cat.png"
|
||||
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
|
||||
// The image file to upload
|
||||
File []byte `protobuf:"bytes,4,opt,name=file,proto3" json:"file,omitempty"`
|
||||
}
|
||||
|
||||
func (x *UploadRequest) Reset() {
|
||||
@@ -88,6 +92,13 @@ func (x *UploadRequest) GetName() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *UploadRequest) GetFile() []byte {
|
||||
if x != nil {
|
||||
return x.File
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type UploadResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -317,6 +328,8 @@ func (x *CropOptions) GetAnchor() string {
|
||||
// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
|
||||
// If one of width or height is 0, the image aspect ratio is preserved.
|
||||
// Optional cropping.
|
||||
// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json
|
||||
// with each parameter as a form field.
|
||||
type ResizeRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -336,6 +349,8 @@ type ResizeRequest struct {
|
||||
// if provided, after resize, the image
|
||||
// will be cropped
|
||||
CropOptions *CropOptions `protobuf:"bytes,7,opt,name=cropOptions,proto3" json:"cropOptions,omitempty"`
|
||||
// The image file to resize
|
||||
File []byte `protobuf:"bytes,8,opt,name=file,proto3" json:"file,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ResizeRequest) Reset() {
|
||||
@@ -419,6 +434,13 @@ func (x *ResizeRequest) GetCropOptions() *CropOptions {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ResizeRequest) GetFile() []byte {
|
||||
if x != nil {
|
||||
return x.File
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ResizeResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -476,6 +498,8 @@ func (x *ResizeResponse) GetUrl() string {
|
||||
|
||||
// Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64),
|
||||
// or by uploading the conversion result.
|
||||
// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json
|
||||
// with each parameter as a form field.
|
||||
type ConvertRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -489,6 +513,8 @@ type ConvertRequest struct {
|
||||
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
|
||||
// make output a URL and not a base64 response
|
||||
OutputURL bool `protobuf:"varint,4,opt,name=outputURL,proto3" json:"outputURL,omitempty"`
|
||||
// The image file to convert
|
||||
File []byte `protobuf:"bytes,5,opt,name=file,proto3" json:"file,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ConvertRequest) Reset() {
|
||||
@@ -551,6 +577,13 @@ func (x *ConvertRequest) GetOutputURL() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *ConvertRequest) GetFile() []byte {
|
||||
if x != nil {
|
||||
return x.File
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ConvertResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -697,74 +730,78 @@ var File_proto_image_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_proto_image_proto_rawDesc = []byte{
|
||||
0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x12, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x22, 0x4d, 0x0a, 0x0d, 0x55, 0x70,
|
||||
0x6f, 0x74, 0x6f, 0x12, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x22, 0x61, 0x0a, 0x0d, 0x55, 0x70,
|
||||
0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62,
|
||||
0x61, 0x73, 0x65, 0x36, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73,
|
||||
0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x22, 0x0a, 0x0e, 0x55, 0x70, 0x6c,
|
||||
0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x75,
|
||||
0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x23, 0x0a,
|
||||
0x05, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x05, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||
0x01, 0x79, 0x22, 0x4b, 0x0a, 0x09, 0x52, 0x65, 0x63, 0x74, 0x61, 0x6e, 0x67, 0x6c, 0x65, 0x12,
|
||||
0x1e, 0x0a, 0x03, 0x6d, 0x69, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x69,
|
||||
0x6d, 0x61, 0x67, 0x65, 0x2e, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x03, 0x6d, 0x69, 0x6e, 0x12,
|
||||
0x1e, 0x0a, 0x03, 0x6d, 0x61, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x69,
|
||||
0x6d, 0x61, 0x67, 0x65, 0x2e, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x03, 0x6d, 0x61, 0x78, 0x22,
|
||||
0x53, 0x0a, 0x0b, 0x43, 0x72, 0x6f, 0x70, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x14,
|
||||
0x0a, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x77,
|
||||
0x69, 0x64, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x16, 0x0a, 0x06,
|
||||
0x61, 0x6e, 0x63, 0x68, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x6e,
|
||||
0x63, 0x68, 0x6f, 0x72, 0x22, 0xcf, 0x01, 0x0a, 0x0d, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x12, 0x10,
|
||||
0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x55, 0x52,
|
||||
0x4c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x55,
|
||||
0x52, 0x4c, 0x12, 0x14, 0x0a, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18, 0x05, 0x20, 0x01, 0x28,
|
||||
0x03, 0x52, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67,
|
||||
0x68, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74,
|
||||
0x12, 0x34, 0x0a, 0x0b, 0x63, 0x72, 0x6f, 0x70, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18,
|
||||
0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x43, 0x72,
|
||||
0x6f, 0x70, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x0b, 0x63, 0x72, 0x6f, 0x70, 0x4f,
|
||||
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x3a, 0x0a, 0x0e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65,
|
||||
0x36, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34,
|
||||
0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75,
|
||||
0x72, 0x6c, 0x22, 0x6c, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71,
|
||||
0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03,
|
||||
0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x12,
|
||||
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
|
||||
0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x55, 0x52, 0x4c, 0x18,
|
||||
0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x55, 0x52, 0x4c,
|
||||
0x22, 0x3b, 0x0a, 0x0f, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75,
|
||||
0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x21, 0x0a,
|
||||
0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10,
|
||||
0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c,
|
||||
0x22, 0x10, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||
0x73, 0x65, 0x32, 0xee, 0x01, 0x0a, 0x05, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x06,
|
||||
0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x55,
|
||||
0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69,
|
||||
0x6d, 0x61, 0x67, 0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x12,
|
||||
0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65,
|
||||
0x73, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3a,
|
||||
0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x12, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67,
|
||||
0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x1a, 0x16, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74,
|
||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x44, 0x65,
|
||||
0x6c, 0x65, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x44, 0x65, 0x6c,
|
||||
0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61,
|
||||
0x67, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x69,
|
||||
0x6d, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x69, 0x6c,
|
||||
0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x22, 0x0a,
|
||||
0x0e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72,
|
||||
0x6c, 0x22, 0x23, 0x0a, 0x05, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x05, 0x52, 0x01, 0x79, 0x22, 0x4b, 0x0a, 0x09, 0x52, 0x65, 0x63, 0x74, 0x61, 0x6e,
|
||||
0x67, 0x6c, 0x65, 0x12, 0x1e, 0x0a, 0x03, 0x6d, 0x69, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
|
||||
0x32, 0x0c, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x03,
|
||||
0x6d, 0x69, 0x6e, 0x12, 0x1e, 0x0a, 0x03, 0x6d, 0x61, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b,
|
||||
0x32, 0x0c, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x52, 0x03,
|
||||
0x6d, 0x61, 0x78, 0x22, 0x53, 0x0a, 0x0b, 0x43, 0x72, 0x6f, 0x70, 0x4f, 0x70, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x05, 0x52, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67,
|
||||
0x68, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74,
|
||||
0x12, 0x16, 0x0a, 0x06, 0x61, 0x6e, 0x63, 0x68, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x06, 0x61, 0x6e, 0x63, 0x68, 0x6f, 0x72, 0x22, 0xe3, 0x01, 0x0a, 0x0d, 0x52, 0x65, 0x73,
|
||||
0x69, 0x7a, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61,
|
||||
0x73, 0x65, 0x36, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x73, 0x65,
|
||||
0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x03, 0x75, 0x72, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x75, 0x74, 0x70,
|
||||
0x75, 0x74, 0x55, 0x52, 0x4c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x6f, 0x75, 0x74,
|
||||
0x70, 0x75, 0x74, 0x55, 0x52, 0x4c, 0x12, 0x14, 0x0a, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x18,
|
||||
0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x12, 0x16, 0x0a, 0x06,
|
||||
0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x68, 0x65,
|
||||
0x69, 0x67, 0x68, 0x74, 0x12, 0x34, 0x0a, 0x0b, 0x63, 0x72, 0x6f, 0x70, 0x4f, 0x70, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x69, 0x6d, 0x61, 0x67,
|
||||
0x65, 0x2e, 0x43, 0x72, 0x6f, 0x70, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x0b, 0x63,
|
||||
0x72, 0x6f, 0x70, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x69,
|
||||
0x6c, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x3a,
|
||||
0x0a, 0x0e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||
0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x80, 0x01, 0x0a, 0x0e, 0x43,
|
||||
0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a,
|
||||
0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62,
|
||||
0x61, 0x73, 0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18,
|
||||
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6f,
|
||||
0x75, 0x74, 0x70, 0x75, 0x74, 0x55, 0x52, 0x4c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09,
|
||||
0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x55, 0x52, 0x4c, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x69, 0x6c,
|
||||
0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x3b, 0x0a,
|
||||
0x0f, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||
0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x06, 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x21, 0x0a, 0x0d, 0x44, 0x65,
|
||||
0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75,
|
||||
0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22, 0x10, 0x0a,
|
||||
0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32,
|
||||
0xee, 0x01, 0x0a, 0x05, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x37, 0x0a, 0x06, 0x55, 0x70, 0x6c,
|
||||
0x6f, 0x61, 0x64, 0x12, 0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f,
|
||||
0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67,
|
||||
0x65, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||
0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x14, 0x2e, 0x69,
|
||||
0x6d, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x52, 0x65, 0x73, 0x69, 0x7a,
|
||||
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x07, 0x43,
|
||||
0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x12, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x43,
|
||||
0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e,
|
||||
0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x52, 0x65, 0x73,
|
||||
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74,
|
||||
0x65, 0x12, 0x14, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65,
|
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2e,
|
||||
0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
|
||||
0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x69, 0x6d, 0x61, 0x67,
|
||||
0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -13,6 +13,8 @@ service Image {
|
||||
|
||||
// Upload an image by either sending a base64 encoded image to this endpoint or a URL.
|
||||
// To resize an image before uploading, see the Resize endpoint.
|
||||
// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json
|
||||
// with each parameter as a form field.
|
||||
message UploadRequest {
|
||||
// Base64 encoded image to upload,
|
||||
string base64 = 1;
|
||||
@@ -20,6 +22,8 @@ message UploadRequest {
|
||||
string url = 2;
|
||||
// Output name of the image including extension, ie. "cat.png"
|
||||
string name = 3;
|
||||
// The image file to upload
|
||||
bytes file = 4;
|
||||
}
|
||||
|
||||
message UploadResponse {
|
||||
@@ -51,6 +55,8 @@ message CropOptions {
|
||||
// Resize an image on the fly without storing it (by sending and receiving a base64 encoded image), or resize and upload depending on parameters.
|
||||
// If one of width or height is 0, the image aspect ratio is preserved.
|
||||
// Optional cropping.
|
||||
// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json
|
||||
// with each parameter as a form field.
|
||||
message ResizeRequest {
|
||||
// base64 encoded image to resize,
|
||||
string base64 = 1;
|
||||
@@ -66,6 +72,8 @@ message ResizeRequest {
|
||||
// if provided, after resize, the image
|
||||
// will be cropped
|
||||
CropOptions cropOptions = 7;
|
||||
// The image file to resize
|
||||
bytes file = 8;
|
||||
}
|
||||
|
||||
message ResizeResponse {
|
||||
@@ -75,6 +83,8 @@ message ResizeResponse {
|
||||
|
||||
// Convert an image from one format (jpeg, png etc.) to an other either on the fly (from base64 to base64),
|
||||
// or by uploading the conversion result.
|
||||
// To use the file parameter you need to send the request as a multipart/form-data rather than the usual application/json
|
||||
// with each parameter as a form field.
|
||||
message ConvertRequest {
|
||||
// base64 encoded image to resize,
|
||||
string base64 = 1;
|
||||
@@ -84,6 +94,8 @@ message ConvertRequest {
|
||||
string name = 3;
|
||||
// make output a URL and not a base64 response
|
||||
bool outputURL = 4;
|
||||
// The image file to convert
|
||||
bytes file = 5;
|
||||
}
|
||||
|
||||
message ConvertResponse {
|
||||
|
||||
Reference in New Issue
Block a user