title: How can I handle multiple file upload requests in the right way?
body: <p>Working on a project which has lots of image upload. And every image gets resized and thumbnailed.</p>
  
  <p>At first I've tried to handle the upload of all images with a single request and when I test it in the server it gave Response Timeout Error.</p>
  
  <p>Now I send request for each file to be uploaded and this seems to be slowing down the server.</p>
  
  <p>Do you have any suggestions for me?</p>
  
  <p>My code:</p>
  
  <pre><code>func SavePhotoWithBuffer(bigBuf, thumbBuf bytes.Buffer, bigSize, thumbSize int64, fileName, contentType string) {
      params := &amp;s3.PutObjectInput{
          Bucket:        aws.String("bucket"),
          Key:           aws.String(fileName),
          Body:          bytes.NewReader(bigBuf.Bytes()),
          ACL:           aws.String("public-read"),
          ContentLength: aws.Int64(bigSize),
          ContentType:   aws.String(contentType),
      }
      thumbParams := &amp;s3.PutObjectInput{
          Bucket:        aws.String("bucket"),
          Key:           aws.String("t_" + fileName),
          Body:          bytes.NewReader(thumbBuf.Bytes()),
          ACL:           aws.String("public-read"),
          ContentLength: aws.Int64(thumbSize),
          ContentType:   aws.String(contentType),
      }
      UploadWithParams(params, thumbParams)
  }
  
  //I've used github.com/patrickmn/go-cache package to cache the session.
  func Open() *s3.S3 {
      var cachedData = cacheservice.GetCache("s3session")
      if cachedData == nil {
          var sess *s3.S3
          accessKey := "accessKey"
          secretKey := "secretKey"
          token := ""
          cred := credentials.NewStaticCredentials(accessKey, secretKey, token)
          _, err := cred.Get()
          if err != nil {
              fmt.Printf("bad credentials: %s", err)
          }
          conf := aws.NewConfig().WithRegion("eu-west-1").WithCredentials(cred)
          conf.Endpoint = aws.String("ams3.digitaloceanspaces.com")
          sess = s3.New(session.New(), conf)
          cacheservice.SetCache("s3session", sess)
          return sess
      }
      return cachedData.(*s3.S3)
  }
  
  
  func UploadWithParams(params, thumbParams *s3.PutObjectInput) {
      var se = Open()
      var err error
      _, err = se.PutObject(params)
      if err != nil {
          fmt.Printf("bad response: %s", err)
      }
      _, err = se.PutObject(thumbParams)
      if err != nil {
          fmt.Printf("bad response: %s", err)
      }
  }
  </code></pre>