anchor.diff:              {ok, UploadRef} = couch:attach("user_uploads", FileKey, {Filename, stream}, Opts),
   
               %% commit upload
  -            {ok, {ResultList}, Req3, _} = stream_file(Req2, UploadRef, CryptoState),
  +            {ok, {ResultList}, Req3, _} = stream_receive_file(Req2, UploadRef, CryptoState),
   
               Rev1 = proplists:get_value(<<"rev">>, ResultList),
               Id = proplists:get_value(<<"id">>, ResultList),
  
positive.code:     {more, Body, Req2} ->
        {NewCryptoState, CipherBody} = crypto:stream_encrypt(CryptoState, Body),
        ok = couch:stream_attach(UploadRef, CipherBody),
        stream_file(Req2, UploadRef, NewCryptoState)
    end.
negative.code: 
                    case Attachment of
                      false -> echo(200, jiffy:encode({FileKVList}), Req);
                      _ ->
                        CType = proplists:get_value(<<"ctype">>, FileKVList),
                        FileName = proplists:get_value(<<"filename">>, FileKVList),
  
                        case couch:fetch_attachment_stream("user_uploads", FileKey, FileName) of
                          {ok, StreamRef} ->
  
                            EncrState = crypto:stream_init(aes_ctr, AESKey, AESIV),
  
                            StreamFun = fun(SendChunk) ->
                              stream_send_file(SendChunk, StreamRef, EncrState, Req)
                            end,
                            Req2 = cowboy_req:set_resp_body_fun(chunked, StreamFun, Req),
  
                            cowboy_req:reply(200, [
                              {<<"content-type">>, CType},
                              {<<"server">>, <<"myinbox-datastore">>}
                            ], Req2);
  
                          _ -> end_with_failure(404, "Not Found", Req)
                        end
  