I use this controller:
public class uploadphotosController : ApiController
{
public Task<HttpResponseMessage> Post( )
{
// Check if the request contains multipart/form-data.
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
string root =HostingEnvironment.MapPath("~/photos");//Burdaki app data klasoru degisecek
var provider = new MultipartFormDataStreamProvider(root);
// Read the form data and return an async task.
var task = Request.Content.ReadAsMultipartAsync(provider).
ContinueWith<HttpResponseMessage>(t =>
{
if (t.IsFaulted || t.IsCanceled)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception);
}
// This illustrates how to get the file names.
foreach (MultipartFileData file in provider.FileData)
{
string fileName = file.LocalFileName;
string originalName = file.Headers.ContentDisposition.FileName;
FileInfo file2 = new FileInfo(fileName);
file2.CopyTo(Path.Combine(root, originalName.TrimStart('"').TrimEnd('"')), true);
file2.Delete();
//Trace.WriteLine(file.Headers.ContentDisposition.FileName);
// Trace.WriteLine("Server file path: " + file.LocalFileName);
}
return Request.CreateResponse(HttpStatusCode.OK);
});
return task;
}
}
And I use this in WebApiConfig.cs
config.Routes.MapHttpRoute(
name: "DefaultApi_uploadphotos",
routeTemplate: "api/{ext}/uploadphotos/",
defaults: new
{
controller = "uploadphotos"
});
It works fine, but I need to upload image with send email and password at the same time. Because I want to upload image if a user is exists. In my way everyone uploads photo as a user or not. I want to send image and some parameters like email and passwords to the same web api.
How can I do that?
thanks in advance
?email=email&password=pw
and then you should use HTTPS since you're passing passwords in clear text (at least I presume) – GrammerPost(string email, string pw)
then you can access those in your body, post to url with query params like sohttp://yoursite.com/uploadphotos?email=whatever&pw=b4df00d
and the image attachments – Grammer