本文整理汇总了Golang中github.com/app-kit/go-appkit.File.GetBackendName方法的典型用法代码示例。如果您正苦于以下问题:Golang File.GetBackendName方法的具体用法?Golang File.GetBackendName怎么用?Golang File.GetBackendName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/app-kit/go-appkit.File
的用法示例。
在下文中一共展示了File.GetBackendName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Delete
func (h *FileService) Delete(f kit.File, u kit.User) apperror.Error {
// Delete file from backend.
if f.GetBackendName() != "" && f.GetBackendId() != "" {
backend := h.Backend(f.GetBackendName())
if backend == nil {
h.Registry().Logger().Errorf("Deleting file %v in backend %v, which is unconfigured", f.GetId(), f.GetBackendName())
} else {
if err := backend.DeleteFile(f); err != nil {
return err
}
}
}
return h.resource.Delete(f, u)
}
示例2: BuildFile
func (h FileService) BuildFile(file kit.File, user kit.User, deleteDir, deleteFile bool) apperror.Error {
if h.DefaultBackend == nil {
return &apperror.Err{
Code: "no_default_backend",
Message: "Cant build a file without a default backend.",
}
}
filePath := file.GetTmpPath()
if filePath == "" {
return &apperror.Err{
Code: "no_tmp_path",
Message: "You must set TmpPath on a file before building it.",
Public: true,
}
}
if file.GetBackendName() == "" {
file.SetBackendName(h.DefaultBackend().Name())
}
backend := h.Backend(file.GetBackendName())
if backend == nil {
return &apperror.Err{
Code: "unknown_backend",
Message: fmt.Sprintf("The backend %v does not exist", file.GetBackendName()),
}
}
file.SetBackend(backend)
if file.GetBucket() == "" {
return &apperror.Err{
Code: "missing_bucket",
Message: "Bucket must be set on the file",
}
}
stat, err := os.Stat(filePath)
if err != nil {
if err == os.ErrNotExist {
return &apperror.Err{
Code: "file_not_found",
Message: fmt.Sprintf("File %v does not exist", filePath),
}
}
return apperror.Wrap(err, "stat_error",
fmt.Sprintf("Could not get file stats for file at %v: %v", filePath, err))
}
if stat.IsDir() {
return apperror.New("path_is_directory")
}
// Build the hash.
hash, err2 := utils.BuildFileMD5Hash(filePath)
if err2 != nil {
return err2
}
file.SetHash(hash)
pathParts := strings.Split(filePath, string(os.PathSeparator))
fullName := pathParts[len(pathParts)-1]
nameParts := strings.Split(fullName, ".")
// Determine extension.
extension := ""
if len(nameParts) > 1 {
extension = nameParts[len(nameParts)-1]
}
file.SetFullName(fullName)
file.SetSize(stat.Size())
// Determine mime type.
mimeType := GetMimeType(filePath)
if mimeType == "" {
mimeType = mime.TypeByExtension("." + extension)
}
file.SetMime(mimeType)
if strings.HasPrefix(mimeType, "image") {
file.SetIsImage(true)
file.SetMediaType(MEDIA_TYPE_IMAGE)
// Determine image info.
imageInfo, err := GetImageInfo(filePath)
if imageInfo != nil {
file.SetWidth(int(imageInfo.Width))
file.SetHeight(int(imageInfo.Height))
} else {
h.Registry().Logger().Warningf("Could not determine image info: %v", err)
}
}
if strings.HasPrefix(mimeType, "video") {
file.SetMediaType(MEDIA_TYPE_VIdEO)
}
//.........这里部分代码省略.........