MCPcopy
hub / github.com/pocketbase/pocketbase / UploadMultipart

Method UploadMultipart

tools/filesystem/filesystem.go:260–300  ·  view source on GitHub ↗

UploadMultipart uploads the provided multipart file to the fileKey location.

(fh *multipart.FileHeader, fileKey string)

Source from the content-addressed store, hash-verified

258
259// UploadMultipart uploads the provided multipart file to the fileKey location.
260func (s *System) UploadMultipart(fh *multipart.FileHeader, fileKey string) error {
261 f, err := fh.Open()
262 if err != nil {
263 return err
264 }
265 defer f.Close()
266
267 mt, err := mimetype.DetectReader(f)
268 if err != nil {
269 return err
270 }
271
272 // rewind
273 f.Seek(0, io.SeekStart)
274
275 originalName := fh.Filename
276 if len(originalName) > 255 {
277 // keep only the first 255 chars as a very rudimentary measure
278 // to prevent the metadata to grow too big in size
279 originalName = originalName[:255]
280 }
281 opts := &blob.WriterOptions{
282 ContentType: mt.String(),
283 Metadata: map[string]string{
284 metadataOriginalName: originalName,
285 },
286 }
287
288 w, err := s.bucket.NewWriter(s.ctx, fileKey, opts)
289 if err != nil {
290 return err
291 }
292
293 _, err = w.ReadFrom(f)
294 if err != nil {
295 w.Close()
296 return err
297 }
298
299 return w.Close()
300}
301
302// Delete deletes stored file at fileKey location.
303//

Callers 1

Calls 7

ReadFromMethod · 0.95
CloseMethod · 0.95
SeekMethod · 0.80
NewWriterMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by 1