anchor.diff:  
       %% @doc Replace the file, no mime check needed.
       replace_file_mime_ok(File, RscId, Props, PropsMedia, Context) ->
  -        case z_acl:rsc_editable(RscId, Context) orelse not(m_rsc:p(RscId, is_authoritative, Context)) of
  +        case RscId == insert_rsc orelse z_acl:rsc_editable(RscId, Context) orelse not(m_rsc:p(RscId, is_authoritative, Context)) of
               true ->
                   Mime = proplists:get_value(mime, PropsMedia),
                   SafeRootName = z_string:to_rootname(proplists:get_value(original_filename, Props, File)),
  
positive.code:                 ArchiveFile = z_media_archive:archive_copy_opt(File, SafeFilename, Context),
                  RootName = filename:rootname(filename:basename(ArchiveFile)),
                  MediumRowProps = [
                      {id, RscId}, 
                      {filename, ArchiveFile}, 
                      {rootname, RootName}, 
                      {is_deletable_file, not z_media_archive:is_archived(File, Context)}
                      | PropsMedia
                  ],
  
                  %% When the resource is in the media category, then move it to the correct sub-category depending
                  %% on the mime type of the uploaded file.
                  case rsc_is_media_cat(RscId, Context) of
                      true -> m_rsc:update(RscId, [{category, mime_to_category(Mime)}], Context);
                      false -> m_rsc:touch(RscId, Context)
                  end,
  
                  F = fun(Ctx) ->
                      z_db:delete(medium, RscId, Context),
                      case z_db:insert(medium, MediumRowProps, Ctx) of
                          {ok, _MediaId} ->
                              {ok, RscId};
                          Error ->
                              Error
                      end
                  end,
  
                  Depicts = depicts(RscId, Context),
                  {ok, Id} = z_db:transaction(F, Context),
                  [ z_depcache:flush(DepictId, Context) || DepictId <- Depicts ],
                  z_depcache:flush(Id, Context),
                  m_rsc:get(Id, Context), %% Prevent side effect that empty things are cached?
                  %% Pass the medium record along in the notification; this also fills the depcache (side effect).
                  z_notifier:notify(#media_replace_file{id=Id, medium=m_media:get(Id, Context)}, Context),
  
negative.code: 
  %% Perform the resource management around inserting a file. The ACL is already checked for the mime type.
  %% Runs the final insert inside a transaction so that we can rollback.
  insert_file_mime_ok(File, Props1, PropsMedia, Context) ->
      Props2 = case proplists:get_value(is_published, Props1) of
          undefined -> [{is_published, true} | Props1];
          _ -> Props1
  