store the original uploaded file name as metadata

This commit is contained in:
Gani Georgiev
2022-12-05 14:28:28 +02:00
parent b8cd686b32
commit 599c542c5a
2 changed files with 21 additions and 2 deletions
+9
View File
@@ -133,8 +133,17 @@ func (s *System) UploadMultipart(fh *multipart.FileHeader, fileKey string) error
// rewind
f.Seek(0, io.SeekStart)
originalName := fh.Filename
if len(originalName) > 255 {
// keep only the first 255 chars as a very rudimentary measure
// to prevent the metadata to grow too big in size
originalName = originalName[:255]
}
opts := &blob.WriterOptions{
ContentType: mt.String(),
Metadata: map[string]string{
"original_filename": fh.Filename,
},
}
w, err := s.bucket.NewWriter(s.ctx, fileKey, opts)