35 lines
758 B
Go
35 lines
758 B
Go
package storage
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"mime/multipart"
|
|
"videoweb/pub/storage/proxy"
|
|
)
|
|
|
|
// web后台上传使用, form-data方式上传
|
|
func UploadImage(ctx context.Context, f *multipart.FileHeader, domain string) (path string, err error) {
|
|
if f == nil {
|
|
return "", errors.New("file is nil!")
|
|
}
|
|
var file multipart.File
|
|
if file, err = f.Open(); err != nil {
|
|
return
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
//mtx.Lock()
|
|
//defer mtx.Unlock()
|
|
buffer := bytes.Buffer{}
|
|
if _, err = buffer.ReadFrom(file); err != nil {
|
|
return
|
|
}
|
|
return proxy.UploadImg(f.Filename, buffer.Bytes(), domain)
|
|
}
|
|
|
|
func QueryMedias(ctx context.Context, in *proxy.MediaQueryesReq, domain string) (*proxy.VideoQuerysResult, error) {
|
|
return proxy.QueryMedias(in, domain)
|
|
}
|