def post_object(self, bucket_name, data, metadata=None):
    '''
    Post the object to a specified bucket. The object name will be generated
    by the server uniquely.
    :param bucket_name: The name of the bucket to whom the object is put
    :param data:        The data to put, bytes or a file like object
    :param metadata:    The metadata of the object
    :return: The result of posting action server returns
    '''
    uri = '%s%s/' % (self._config.get_upload_base_uri(), bucket_name)
    if metadata is None:
      metadata = FDSObjectMetadata()
    if self._config.enable_md5_calculate:
      digest = hashlib.md5()
      digest.update(data)
      metadata.add_header(Common.CONTENT_MD5,digest.hexdigest())

    response = self._request.post(uri, data=data, auth=self._auth,
        headers=metadata.metadata)
    if response.status_code == requests.codes.ok:
      return PutObjectResult(to_json_object(response.content))
    headers = ""
    if self._config.debug:
      headers = ' header=%s' % response.headers
    message = 'Post object failed, status=%s, reason=%s%s' % (
        response.status_code, response.content, headers)
    raise GalaxyFDSClientException(message)
 def complete_multipart_upload(self, bucket_name, object_name, upload_id,
   metadata, upload_part_result_list):
   '''
   Complete a multipart upload
   :param bucket_name:
   :param object_name:
   :param upload_id:
   :param metadata:
   :param upload_part_result_list:
   :return:
   '''
   uri = '%s%s/%s?%s' % (
     self._config.get_base_uri(), bucket_name, object_name, "uploadId=" +
     upload_id)
   if metadata is None:
     metadata = FDSObjectMetadata()
   response = self._request.put(uri, auth=self._auth,
     data=upload_part_result_list, headers=metadata.metadata)
   if response.status_code == requests.codes.ok:
     result = PutObjectResult(to_json_object(response.content))
     return result
   else:
     headers = ""
     if self._config.debug:
       headers = ' headers=%s' % response.headers
     message = 'Complete multipart upload failed, status=%s, reason=%s%s' % (
       response.status_code, response.content, headers)
     raise GalaxyFDSClientException(message)
  def put_object(self, bucket_name, object_name, data, metadata=None):
    '''
    Put the object to a specified bucket. If a object with the same name already
    existed, it will be overwritten.
    :param bucket_name: The name of the bucket to whom the object is put
    :param object_name: The name of the object to put
    :param data:        The data to put, bytes or a file like object
    :param metadata:    The metadata of the object
    :return: The result of putting action server returns
    '''
    uri = '%s%s/%s' % (self._config.get_upload_base_uri(), bucket_name,
      object_name)
    if metadata is None:
      metadata = FDSObjectMetadata()
    if self._config.enable_md5_calculate:
      digest = hashlib.md5()
      if IS_PY3:
        if isinstance(data, str):
          data = data.encode(encoding="UTF-8")
          digest.update(data)
        elif data.seekable and data.seekable():
          pos = data.tell()
          digest.update(data.read())
          data.seek(0, pos)
        else:
          raise GalaxyFDSClientException("Cannot digest data")
      else:
        digest.update(data)

      metadata.add_header(Common.CONTENT_MD5, digest.hexdigest())

    response = self._request.put(uri, data=data, auth=self._auth,
        headers=metadata.metadata)
    if response.status_code == requests.codes.ok:
      return PutObjectResult(to_json_object(response.content))
    headers = ""
    if self._config.debug:
      headers = ' header=%s' % response.headers
    message = 'Put object failed, status=%s, reason=%s%s' % (
        response.status_code, response.content, headers)
    raise GalaxyFDSClientException(message)