mirror of
https://github.com/Luzifer/share.git
synced 2024-12-20 10:31:16 +00:00
Provide a fallback mime type
This commit is contained in:
parent
db4f618a6d
commit
200dcb187d
3 changed files with 8 additions and 2 deletions
1
cmd/share/.gitignore
vendored
Normal file
1
cmd/share/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
share
|
|
@ -46,6 +46,11 @@ func main() {
|
|||
|
||||
inFile := rconfig.Args()[1]
|
||||
upFile := path.Join(cfg.BasePath, path.Base(inFile))
|
||||
mimeType := mime.TypeByExtension(path.Ext(inFile))
|
||||
if mimeType == "" {
|
||||
mimeType = "application/octet-stream"
|
||||
}
|
||||
|
||||
inFileHandle, err := os.Open(inFile)
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("Unable to open source file")
|
||||
|
@ -62,7 +67,7 @@ func main() {
|
|||
log.WithError(err).Fatal("Unable to assemble target path")
|
||||
}
|
||||
|
||||
log.Infof("Uploading %q to %q", inFile, upFile)
|
||||
log.Infof("Uploading %q to %q with type %q", inFile, upFile, mimeType)
|
||||
|
||||
sess := session.Must(session.NewSession())
|
||||
svc := s3.New(sess)
|
||||
|
@ -70,7 +75,7 @@ func main() {
|
|||
if _, err := svc.PutObject(&s3.PutObjectInput{
|
||||
Body: inFileHandle,
|
||||
Bucket: aws.String(cfg.Bucket),
|
||||
ContentType: aws.String(mime.TypeByExtension(path.Ext(inFile))),
|
||||
ContentType: aws.String(mimeType),
|
||||
Key: aws.String(upFile),
|
||||
}); err != nil {
|
||||
log.WithError(err).Fatalf("Unable to put file into S3")
|
||||
|
|
BIN
cmd/share/share
BIN
cmd/share/share
Binary file not shown.
Loading…
Reference in a new issue