github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/pkg/blobserver/s3/receive.go (about) 1 /* 2 Copyright 2011 Google Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package s3 18 19 import ( 20 "bytes" 21 "crypto/md5" 22 "io" 23 24 "camlistore.org/pkg/blob" 25 ) 26 27 func (sto *s3Storage) ReceiveBlob(b blob.Ref, source io.Reader) (sr blob.SizedRef, err error) { 28 var buf bytes.Buffer 29 md5h := md5.New() 30 31 size, err := io.Copy(io.MultiWriter(&buf, md5h), source) 32 if err != nil { 33 return sr, err 34 } 35 36 if faultReceive.FailErr(&err) { 37 return 38 } 39 40 err = sto.s3Client.PutObject(b.String(), sto.bucket, md5h, size, &buf) 41 if err != nil { 42 return sr, err 43 } 44 return blob.SizedRef{Ref: b, Size: uint32(size)}, nil 45 }