-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support file upload #60
Comments
I think we have one in the wiki.
…On Jan 17, 2017 4:22 PM, "bufferUnderrun" ***@***.***> wrote:
Hi,
Do you have a code snippet to handle file uploading from a html form <input
type="file" /> ?
Thanks,
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#60>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABsYsBqindTy6DJVyKED_iLnUqW6Qf_Cks5rTT8zgaJpZM4LmPQm>
.
|
yep in https://github.com/unosquare/embedio/wiki/Cookbook you use the http://stackoverflow.com/a/21689347/3699737 code snippet. But i don't see how to pass the |
This is a functional method that we use in other project with EmbedIO and the nuget HttpMultipartParser: [WebApiHandler(HttpVerbs.Post, "/api/upload")]
public bool UploadCert(WebServer server, HttpListenerContext context)
{
try
{
var parser = new MultipartFormDataParser(context.Request.InputStream);
if (parser.Files.Any() == false)
throw new Exception("Invalid request, you need to post a file");
using (var ms = new MemoryStream())
{
parser.Files.First().Data.CopyTo(ms);
var path = Path.Combine(CurrentApp.EntryAssemblyDirectory, RelayService.Constants.DefaultCertName);
File.WriteAllBytes(path, ms.ToArray());
SettingsProvider<AppSettings>.Instance.Global.SmtpServerCertificateFile = path;
SettingsProvider<AppSettings>.Instance.Global.SmtpServerCertificatePassword = parser.Parameters.First().Data;
SettingsProvider<AppSettings>.Instance.PersistGlobalSettings();
}
Task.Factory.StartNew(() => StartupService.Current.Restart());
context.Response.Redirect("/");
return true;
}
catch (Exception ex)
{
return HandleError(context, ex);
}
} |
Closing ticket. |
Closed
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Do you have a code snippet to handle file uploading from a html form
<input type="file" />
?Thanks,
The text was updated successfully, but these errors were encountered: