anchor.diff:      {more, Body, Req2} ->
         {NewCryptoState, CipherBody} = crypto:stream_encrypt(CryptoState, Body),
         ok = couch:stream_attach(UploadRef, CipherBody),
  -      stream_file(Req2, UploadRef, NewCryptoState)
  +      stream_receive_file(Req2, UploadRef, NewCryptoState)
  +  end.
  +
  +stream_send_file(SendChunk, StreamRef, EncrState, Req) ->
  +  case couchbeam:stream_attachment(StreamRef) of
  +    {ok, EncrResult} ->
  +      {NewEncrState, Result} = crypto:stream_decrypt(EncrState, EncrResult),
  +
  +      SendChunk(Result),
  +
  +      stream_send_file(SendChunk, StreamRef, NewEncrState, Req);
  +    done -> {ok, Req};
  +    {error, Err} ->
  +      end_with_failure(500, "Transport issue", Req),
  +      {error, Err}
     end.
positive.code:             {ok, UploadRef} = couch:attach("user_uploads", FileKey, {Filename, stream}, Opts),
  
              %% commit upload
              {ok, {ResultList}, Req3, _} = stream_file(Req2, UploadRef, CryptoState),
  
              Rev1 = proplists:get_value(<<"rev">>, ResultList),
              Id = proplists:get_value(<<"id">>, ResultList),
  
negative.code:       {ok, Req2, FieldList, FileList}
    end.
  
  stream_receive_file(Req, UploadRef, CryptoState) ->
    case cowboy_req:part_body(Req) of
      {ok, Body, Req2} ->
        {NewCryptoState, CipherBody} = crypto:stream_encrypt(CryptoState, Body),
  