Web-API: Wie greife ich bei Verwendung von MultipartMemoryStreamProvider auf mehrteilige Formularwerte zu?
Vorher habe ich benutztMultipartFormDataStreamProvider
um mehrteilige Anfragen zu bearbeiten.
Da ich möchte, dass die hochgeladene Datei anstelle einer Festplattendatei im Arbeitsspeicher gespeichert wird, habe ich meinen Code geändertMultipartMemoryStreamProvider
. Das Laden der Datei scheint in Ordnung zu sein, aber ich kann nicht mehr auf andere Formularwerte zugreifen, die über verfügbar warenprovider.FormData
unterMultipartFormDataStreamProvider
. Könnte mir jemand zeigen, wie das geht?
Die rohe Anfrage von Fiddler erfasst:
POST http://myserver.com/QCCSvcHost/MIME/RealtimeTrans/ HTTP/1.1
Content-Type: multipart/form-data; boundary="XbCY"
Host: na-w-lxu3
Content-Length: 1470
Expect: 100-continue
Connection: Keep-Alive
--XbCY
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=PayloadType
X12_270_Request_005010X279A1
--XbCY
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=ProcessingMode
RealTime
--XbCY
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=PayloadID
e51d4fae-7dec-11d0-a765-00a0c91e6fa6
--XbCY
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=TimeStamp
2007-08-30T10:20:34Z
--XbCY
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=SenderID
HospitalA
--XbCY
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=ReceiverID
PayerB
--XbCY
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=CORERuleVersion
2.2.0
--XbCY
Content-Disposition: form-data; name=Payload; filename=276_5010.edi
ISA*00*~SE*16*0001~GE*1*1~IEA*1*191543498~
--XbCY--
Mein Controller-Code:
string payload = null;
NameValueCollection nvc = null;
string fname = null;
StringBuilder sb = new StringBuilder();
sb.AppendLine();
foreach (StreamContent item in provider.Contents)
{
fname = item.Headers.ContentDisposition.FileName;
if (!String.IsNullOrWhiteSpace(fname))
{
payload = item.ReadAsStringAsync().Result;
}
else
{
nvc = item.ReadAsFormDataAsync().Result;
}
}