How can I directly upload files to url ex .info and .dat files? file path is not available because I am sending from GPRS module so I made this code:
[Route("api/b")]
//[BasicAuthentication]
[HttpPost]
public async Task<IHttpActionResult> PostFiles()
{
var result = await Request.Content.ReadAsStringAsync();
try
{
//WriteMsg(result, fileName);
return Ok();
}
catch (Exception e)
{
//LogError(e);
return ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
}
}
private void WriteMsg(string result)
{
string message = string.Format("Time: {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
message += Environment.NewLine;
message += "-----------------------------------------------------------";
message += result;
//var statusInfoName = result.Contains(x => x.)
string path = HttpContext.Current.Server.MapPath("~/UploadedFiles/string.txt");
using (StreamWriter writer = new StreamWriter(path, false))
{
writer.WriteLine(result);
writer.Close();
}
}
it returns this one:
Time: 31/01/2018 01:07:28 PM
---------------------------------------------------------------testBoundary
Content-Disposition: form-data;
name="fileToUpload"; filename="status.info"
Content-Type: text/plain
Node Identifier: 020F7E0A0624
Node Info:
BAT:6880|TEMP:1825|RSSI:-79|IMEI:862631032026154|ICCID:89966098132100451574
Batteries: 7151mV
Power Supply Failures: 0
Power Supply Status: 0
System Time: 1517429233
External Resets: 48
Power Fail Resets: 1
----testBoundary
Time: 31/01/2018 01:07:34 PM
-------testBoundary
Content-Disposition: form-data;
name="fileToUpload"; filename="WmbusData.dat"
Content-Type: text/plain
JFpSAQgfRK5McZAkEGgHekowEAX3E3Vw1flfodnLaHnPyf+bUg==
----testBoundary
I want to separate file status.info and WmbusData.dat because when I am using ReadAsStringAsync().
Aucun commentaire:
Enregistrer un commentaire