角度上传405(不允许使用方法) [英] Angular upload 405 (Method Not Allowed)
本文介绍了角度上传405(不允许使用方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当尝试上传有角度的图像时出现错误405(不允许使用方法)
When try upload images with angular get error 405 (Method Not Allowed)
我要在源文件中更改标题,但是还是出现错误,有解决办法吗?
I'm change headers im my source but again error, any solution?
将URL更改为 https://angular-file-upload-cors- srv.appspot.com/upload 在我的目的地无法正常工作!
When change URL to https://angular-file-upload-cors-srv.appspot.com/upload work fine on my destination not working!
推荐答案
您的目的地必须是处理POST的Web API. 像这样的东西:
Your destination needs to be Web API that handles POST. Something like that:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
namespace WebAPI.Controllers
{
public class FileUploadController : ApiController
{
public HttpResponseMessage Post()
{
HttpResponseMessage result = null;
var httpRequest = HttpContext.Current.Request;
if (httpRequest.Files.Count > 0)
{
var docfiles = new List<string>();
foreach (string file in httpRequest.Files)
{
var postedFile = httpRequest.Files[file];
var filePath = HttpContext.Current.Server.MapPath("~/images/" + postedFile.FileName);
postedFile.SaveAs(filePath);
docfiles.Add(filePath);
}
result = Request.CreateResponse(HttpStatusCode.Created, docfiles);
}
else
{
result = Request.CreateResponse(HttpStatusCode.BadRequest);
}
return result;
}
}
}
See step-by-step here. If you need asynchronous upload, check out this.
MapPath中的〜/images/"可以是虚拟文件夹.
The "~/images/" in the MapPath can be a virtual folder.
这篇关于角度上传405(不允许使用方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文