code: func (c *Client) UploadFile(ctx context.Context, filename string, contents io.Reader, opts *FileUploadOptions) (blob.Ref, error) {
  	fileMap := schema.NewFileMap(filename)
  	if opts != nil && opts.FileInfo != nil {
  		fileMap = schema.NewCommonFileMap(filename, opts.FileInfo)
  		modTime := opts.FileInfo.ModTime()
  		if !modTime.IsZero() {
  			fileMap.SetModTime(modTime)
  		}
  	}
  	fileMap.SetType("file")
  
  	var wholeRef []blob.Ref
  	if opts != nil && opts.WholeRef.Valid() {
  		wholeRef = append(wholeRef, opts.WholeRef)
  	} else {
  		var buf bytes.Buffer
  		var err error
  		wholeRef, err = c.wholeRef(io.TeeReader(contents, &buf))
  		if err != nil {
  			return blob.Ref{}, err
  		}
  		contents = io.MultiReader(&buf, contents)
  	}
  
  	fileRef, err := c.fileMapFromDuplicate(ctx, fileMap, wholeRef)
  	if err != nil {
  		return blob.Ref{}, err
  	}
  	if fileRef.Valid() {
  		return fileRef, nil
  	}
  
  	return schema.WriteFileMap(ctx, c, fileMap, contents)
  }
docs: // UploadFile uploads the contents of the file, as well as a file blob with
  // filename for these contents. If the contents or the file blob are found on
  // the server, they're not uploaded.
  //
  // Note: this method is still a work in progress, and might change to accommodate
  // the needs of pk-put file.