50 lines
760 B
Go
50 lines
760 B
Go
package connector
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type FileMediaObject struct {
|
|
Path string
|
|
}
|
|
|
|
func (m *FileMediaObject) Filename() string {
|
|
return filepath.Base(m.Path)
|
|
}
|
|
|
|
func (m *FileMediaObject) Size() int64 {
|
|
fi, err := os.Stat(m.Path)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return fi.Size()
|
|
}
|
|
|
|
func (m *FileMediaObject) Mimetype() string {
|
|
f, err := os.Open(m.Path)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer f.Close()
|
|
|
|
buffer := make([]byte, 512)
|
|
_, err = f.Read(buffer)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
return http.DetectContentType(buffer)
|
|
}
|
|
|
|
func (m *FileMediaObject) Read() (io.ReadCloser, error) {
|
|
return os.Open(m.Path)
|
|
}
|
|
|
|
func (m *FileMediaObject) URL() string {
|
|
return ""
|
|
}
|