code: public void actionReplace() throws JspException {
  
          try {
              // get the file item from the multipart request
              Iterator<FileItem> i = getMultiPartFileItems().iterator();
              FileItem fi = null;
              while (i.hasNext()) {
                  fi = i.next();
                  if (fi.getName() != null) {
                      // found the file object, leave iteration
                      break;
                  }
              }
  
              if (fi != null) {
                  // get file object information
                  long size = fi.getSize();
                  long maxFileSizeBytes = OpenCms.getWorkplaceManager().getFileBytesMaxUploadSize(getCms());
                  // check file size
                  if ((maxFileSizeBytes > 0) && (size > maxFileSizeBytes)) {
                      // file size is larger than maximum allowed file size, throw an error
                      throw new CmsException(
                          Messages.get().container(
                              Messages.ERR_FILE_SIZE_TOO_LARGE_1,
                              new Long((maxFileSizeBytes / 1024))));
                  }
                  byte[] content = fi.get();
                  fi.delete();
  
                  // determine the resource type id from the resource to replace
                  CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
                  CmsFile file = getCms().readFile(res);
                  byte[] contents = file.getContents();
                  int resTypeId = res.getTypeId();
                  // check the lock state and replace resource
                  checkLock(getParamResource());
                  try {
                      getCms().replaceResource(getParamResource(), resTypeId, content, null);
                  } catch (CmsDbSqlException sqlExc) {
                      // SQL error, probably the file is too large for the database settings, restore old content
                      file.setContents(contents);
                      getCms().writeFile(file);
                      throw sqlExc;
                  }
                  // close dialog
                  actionCloseDialog();
              } else {
                  throw new CmsException(Messages.get().container(Messages.ERR_UPLOAD_FILE_NOT_FOUND_0));
              }
          } catch (Throwable e) {
              // error replacing file, show error dialog
              includeErrorpage(this, e);
          }
      }
docs: Uploads the specified file and replaces the VFS file.<p>
  
  @throws JspException if inclusion of error dialog fails