Excellent , this work fine
I attach the final sample code
s3Svc := s3.New(session.New(&aws.Config{Region:
aws.String("us-west-2")}))
result, err := s3Svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
})
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
io.Copy(os.Stdout, result.Body)
result.Body.Close()
Thanks so much
El jueves, 30 de junio de 2016, 0:53:31 (UTC-3), Joshua Boelter escribió:
>
> I've been tinkering w/ the AWS Go SDK to get used to it ... this is one
> method using the GetObject API; see the full gist for a working example
>
> https://gist.github.com/jboelter/6f5bd598673eb0e606f10660495fc175
>
>
> s3Svc := s3.New(awsSession)
>
> result, err := s3Svc.GetObject(&s3.GetObjectInput{
> Bucket: aws.String(bucket),
> Key: aws.String(key),
> })
>
> if err != nil {
> fmt.Fprintln(os.Stderr, err)
> os.Exit(1)
> }
>
> n, err := io.Copy(os.Stdout, result.Body)
> result.Body.Close()
>
>
>
> On Wednesday, June 29, 2016 at 3:35:39 PM UTC-7, Walter Garcia wrote:
>>
>> Hello all.
>>
>> Im new using AWS SDK in go and Im need download file object from S3 to
>> Stdout and not create a file.
>> For example:
>> my_download_s3_program > file.txt
>> or
>> my_download_s3_program | tar
>> etc
>>
>> So, I can download to file, but I need stream on the fly to stdout, it's
>> possible?
>>
>> This example write a file:
>> ----------------------------------------------------------------------
>> file, err := os.Create("download_file.txt")
>> if err != nil {
>> fmt.Println("Failed to create file", err)
>> os.Exit(4)
>> }
>> defer file.Close()
>>
>> key := path.Join(prefix, filename)
>>
>> downloader :=
>> s3manager.NewDownloader(session.New(&aws.Config{Region:
>> aws.String("us-west-2")}))
>> numBytes, err := downloader.Download(f,
>> &s3.GetObjectInput{
>> Bucket: aws.String(bucket),
>> Key: aws.String(key),
>> })
>> if err != nil {
>> fmt.Println("Failed to download file", err)
>> os.Exit(5)
>> }
>>
>> fmt.Println("Downloaded file", file.Name(), numBytes, "bytes")
>>
>> ----------------------------------------------------------------------
>>
>> How can modify this example to stream to stdout?
>>
>> Well, thanks in advance.
>>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.