MCPcopy Create free account
hub / github.com/astercloud/aster / NewFileFromPath

Function NewFileFromPath

pkg/media/types.go:293–310  ·  view source on GitHub ↗

NewFileFromPath 从路径创建文件

(path string)

Source from the content-addressed store, hash-verified

291
292// NewFileFromPath 从路径创建文件
293func NewFileFromPath(path string) (*File, error) {
294 data, err := os.ReadFile(path)
295 if err != nil {
296 return nil, fmt.Errorf("failed to read file: %w", err)
297 }
298
299 file := &File{
300 Name: filepath.Base(path),
301 Size: int64(len(data)),
302 Extension: filepath.Ext(path),
303 Data: base64.StdEncoding.EncodeToString(data),
304 }
305
306 // 尝试检测 MIME 类型
307 file.MimeType = detectMimeType(path)
308
309 return file, nil
310}
311
312// detectMimeType 检测 MIME 类型
313func detectMimeType(path string) string {

Callers 1

NewFileFunction · 0.85

Calls 2

detectMimeTypeFunction · 0.85
ReadFileMethod · 0.45

Tested by

no test coverage detected