diff --git a/server/server.go b/server/server.go index aa78bd5..81c0cbc 100644 --- a/server/server.go +++ b/server/server.go @@ -194,11 +194,8 @@ func (s *server) dealWithAuthError(userInRepo auth.UserInRepo, w http.ResponseWr } func (s *server) downloadObject(in *batch.RequestObject, out *batch.Object) { - getObjectMetadataInput := &obs.GetObjectMetadataInput{ - Bucket: s.bucket, - Key: s.key(in.OID), - } - if metadata, err := s.client.GetObjectMetadata(getObjectMetadataInput); err != nil { + getObjectMetadataInput := s.getObjectMetadataInput(s.bucket, s.key(in.OID)) + if metadata, err := s.client.GetObjectMetadata(&getObjectMetadataInput); err != nil { out.Error = &batch.ObjectError{ Code: 404, Message: err.Error(), @@ -237,6 +234,12 @@ func (s *server) uploadObject(in *batch.RequestObject, out *batch.Object) { return } + checkInput := s.getObjectMetadataInput(s.bucket, s.key(in.OID)) + _, err := s.client.GetObjectMetadata(&checkInput) + if err == nil { + return + } + putObjectInput := &obs.CreateSignedUrlInput{} putObjectInput.Method = obs.HttpMethodPut putObjectInput.Bucket = s.bucket @@ -257,6 +260,13 @@ func (s *server) uploadObject(in *batch.RequestObject, out *batch.Object) { } } +func (s *server) getObjectMetadataInput(bucket string, key string) obs.GetObjectMetadataInput { + return obs.GetObjectMetadataInput{ + Bucket: bucket, + Key: key, + } +} + // 生成下载对象的带授权信息的URL func (s *server) generateDownloadUrl(getObjectInput *obs.CreateSignedUrlInput) *url.URL { // 生成下载对象的带授权信息的URL