Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add POST to transparent S3 api #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
log "github.com/sirupsen/logrus"
)

const version string = "0.17.3"
const version string = "0.17.4"

var (
host string
Expand Down Expand Up @@ -174,6 +174,7 @@ func runServer() {
})
router.GET("/:bucket/*key", transparentS3Get)
router.PUT("/:bucket/*key", transparentS3Put)
router.POST("/:bucket/*key", transparentS3Post)
router.DELETE("/:bucket/*key", transparentS3Delete)
}

Expand Down
31 changes: 31 additions & 0 deletions s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"fmt"
"strings"
"sync"

//"net/http"
"time"

"github.com/adrianchifor/go-parallel"
Expand Down Expand Up @@ -180,6 +182,35 @@ func transparentS3Put(c *gin.Context) {
c.String(200, "")
}

func transparentS3Post(c *gin.Context) {
bucket := c.Param("bucket")
key := c.Param("key")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key and bucket need empty string checks

//file := c.Param("file")
uploads, ok := c.Get("uploads")
log.Debugf("Upload Params:", uploads)
if !ok {
log.Debugf("Uploads Param exists, starting new multi-part post upload")
input := &s3.CreateMultipartUploadInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
//ContentType: aws.String(fileType),
}

resp, err := s3Client.CreateMultipartUpload(input)
if err != nil {
fmt.Println(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Println(err.Error())
log.Errorf("Failed to create multipart upload: %v", err)

return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to set the context before returning, like c.String(500, "")

}
log.Debugf("Response: ", resp)
c.XML(200, resp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resp is a go struct, not XML https://docs.aws.amazon.com/sdk-for-go/api/service/s3/#CreateMultipartUploadOutput

It depends on what the multipart POST expects as a response, either you need a new XML struct in https://github.com/MarshallWace/cachenator/blob/master/s3_structs.go or a plain response like for transparent put c.String(200, "")

//c.Data(http.StatusOK, "text/html; charset=utf-8", []byte(resp.String()))

}

log.Debugf("Uploads %s request started '%s#%s' from S3", uploads, bucket, key)

}

func transparentS3Get(c *gin.Context) {
bucket := c.Param("bucket")
key := c.Param("key")
Expand Down