My client app will be sending me an image file and a video file through Multi part form data stream. And i want to store the image file in image folder and the video file in the video folder.
This is how the request from the client looks like
Content-Disposition: form-data; name="Photo"; filename="IMG_9322.JPG" Content-Type:application/octet-stream
Content-Disposition: form-data; name="Video"; filename="sample.avi" Content-Type:application/octet-stream
And this is the Api controller method at my end
[HttpPost]
[ActionName("UploadVideoEntry")]
public async Task<HttpResponseMessage> UploadVideoEntry()
{
// Check if the request contains multipart/form-data.
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var folderName = "photos";
string root = HttpContext.Current.Server.MapPath("~/" + folderName);
var provider = new MultipartFormDataStreamProvider(root);
try
{
// Read the form data and return an async task.
var response = await Request.Content.ReadAsMultipartAsync(provider);
return Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage<Object> { success = true, message = "Media Uploaded" });
}
catch (System.Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
}
}
This stores both the files in the photo folder because thats the path i have given. But i dont know how i can separate both the files and store them in different paths. Please let me know if anyone has any idea? Thanks