It is not possible to tell from your code if that is the correct data or not.  
You code did not display the data it was sending (that might be illuminating).  
Are you sure that when you are reading the file you are displaying what was 
actually there?

Also, why are you specifying:

        ContentLength: aws.Int64(int64(len(fileData))),
        ContentType:   aws.String(http.DetectContentType([]byte(fileData))),

The ContentLength should be automatically determined if not set.  Do you know 
what ContentType is being set to?

I have code that looks like:

// var data []byte
// var bucket, name string
        _, err := awss3.PutObject(&s3.PutObjectInput{
                Body:   bytes.NewReader(data),
                Bucket: &bucket,
                Key:    &name,
        })

Which seems to write to S3 what I want.  To read the data I use:

        obj, err := awss3.GetObject(&s3.GetObjectInput{
                Bucket: &bucket,
                Key:    &name,
        })
        if err != nil {
                return nil, err
        }
        return ioutil.ReadAll(obj.Body)

Those have appeared to work for me.

    -Paul

On Sep 17, 2018, at 6:48 PM, agruet...@gmail.com<mailto:agruet...@gmail.com> 
wrote:

OK, I know I am doing something dumb and have a case of the Monday's. If anyone 
is able to point out my stupid it would be much appreciated.

Output when opening the file in S3:

0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
7465 7374 2e65 6273 5f66 6163 745f 6773
742d 7161 6c2e 6170 705f 696e 6672 6173
7472 7563 7475 7265 5f70 6572 662e 6562
735f 6661 6374 5f67 7374 2d71 616c 2d61
7070 2e69 6e64 6976 6964 7561 6c5f 6e6f
6465 732e 7071 616c 6773 7461 736b 3031
636f 7270 696e 7475 6974 6e65 742e 6861
7264 7761 7265 5f72 6573 6f75 7263 6573
2e6e 6574 776f 726b 2e69 6e63 6f6d 696e
675f 6b62 2f73 6563 2035 2031 3533 3732
3237 3036 3020 0a00 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000

Code:

func (controller *controllerDetails) sendMetricBatch() error {
    var err error
    println("HERE89")
    if controller.sendBuf.buffer.Len() > 0 {
        println("HERE99")
        //Create a UUID filename
        fileName, err := uuid.NewV4()
        if err != nil {
            panic(err)
        }

        //FIX ME UNHARD CODE BUCKET
        //controller.sendBuf.mux.Lock()
        //defer controller.sendBuf.mux.Unlock()
        //FIXME this byte read is lost if the upload fails
        _, err = awss3.PutFileBytes(controller.s3Client, "appdoimbuckettest", 
fileName.String(), controller.sendBuf.buffer.Bytes())
        if err != nil {
            println("FML123")
            panic(err)
        }
    }
    return err
}

func PutFileBytes(s3Client *s3.S3, s3Bucket, copyTo string, fileData []byte) 
(*s3.PutObjectOutput, error) {
    var err error

    putInput := &s3.PutObjectInput{
        Body: bytes.NewReader(fileData),
        Bucket: aws.String(s3Bucket),
        Key: aws.String(copyTo),
        ContentLength: aws.Int64(int64(len(fileData))),
        ContentType: aws.String(http.DetectContentType([]byte(fileData))),
    }

    results, err := s3Client.PutObject(putInput)
    if err != nil {
        return nil, err
    }

    return results, err
}

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
golang-nuts+unsubscr...@googlegroups.com<mailto:golang-nuts+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to