MCPcopy
hub / github.com/pocketbase/pocketbase / GetReuploadableFile

Method GetReuploadableFile

tools/filesystem/filesystem.go:140–166  ·  view source on GitHub ↗

GetReuploadableFile constructs a new reuploadable File value from the associated fileKey blob.Reader. If preserveName is false then the returned File.Name will have a new randomly generated suffix, otherwise it will reuse the original one. This method could be useful in case you want to clone an e

(fileKey string, preserveName bool)

Source from the content-addressed store, hash-verified

138// If you simply want to copy an existing file to a new location you
139// could check the Copy(srcKey, dstKey) method.
140func (s *System) GetReuploadableFile(fileKey string, preserveName bool) (*File, error) {
141 attrs, err := s.Attributes(fileKey)
142 if err != nil {
143 return nil, err
144 }
145
146 name := path.Base(fileKey)
147 originalName := attrs.Metadata[metadataOriginalName]
148 if originalName == "" {
149 originalName = name
150 }
151
152 file := &File{}
153 file.Size = attrs.Size
154 file.OriginalName = originalName
155 file.Reader = openFuncAsReader(func() (io.ReadSeekCloser, error) {
156 return s.GetReader(fileKey)
157 })
158
159 if preserveName {
160 file.Name = name
161 } else {
162 file.Name = normalizeName(file.Reader, originalName)
163 }
164
165 return file, nil
166}
167
168// Copy copies the file stored at srcKey to dstKey.
169//

Callers 1

Calls 4

AttributesMethod · 0.95
GetReaderMethod · 0.95
normalizeNameFunction · 0.85
openFuncAsReaderFuncType · 0.70

Tested by 1