我在我的 .Net Core API 中创建了一个方法,它将上传一个文件。
[HttpPost]
public async Task<IActionResult> ReadFile(IFormFile file)
{
return BadRequest(file);
}
Run Code Online (Sandbox Code Playgroud)
我这样做是return BadRequest(file)为了阅读邮递员发送给我的内容。
结果是这样的:
{
"contentDisposition": "form-data; name=\"file\"; filename=\"data.dat\"",
"contentType": "application/octet-stream",
"headers": {
"Content-Disposition": [
"form-data; name=\"file\"; filename=\"data.dat\""
],
"Content-Type": [
"application/octet-stream"
]
},
"length": 200,
"name": "file",
"fileName": "data.dat"
Run Code Online (Sandbox Code Playgroud)
}
我在 Microsoft 文档中看到:
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
// Read the stream to a string, and write the string to the console.
String line = sr.ReadToEnd();
Console.WriteLine(line);
}
Run Code Online (Sandbox Code Playgroud)
但是用户必须选择一个文件来读取它,应用程序不必进入文件夹并读取文件。 …
所以我想在 javascript 中合并相邻的多边形,这就是我在代码中实际拥有的:
我想删除内部描边但保留边框描边。
所以我想从这里开始:
对此:
我想保留巴黎的洞 - 我可以定义哪些多边形必须分组,但我无法将它们与以下代码合并:
var map = L.map('map', {
center: [46.52863469527167, 2.43896484375],
zoom: 6,
maxZoom: 18,
minZoom: 7
});
$http.get("france.json").then(function (response) {
$scope.communeFr = response.data.features
$http.get(apiult).then(function (response) {
$scope.showCommune = response.data.Liste
$scope.communeFr.map(x => {
x.show = false
for (let i = 0; i < $scope.showCommune .length; i++) {
if (x.properties.insee == $scope.showCommune[i].insee) {
x.show = true
return
}
}
})
L.geoJson($scope.communeFr, {
filter: function (feature, latlng) {
return feature.show
}
}).addTo(map);
});
});
Run Code Online (Sandbox Code Playgroud)
更新 - …
我创建了 .Net Core API 并配置了 Windows 身份验证。在我的 angular 应用程序中,我必须在每个请求中添加此选项withCredentials : true。我做了一个放置请求,但它返回给我:
我也尝试发布请求,但它不起作用,只能获取请求工作。
auth.service.ts :
updateUser(id,lastlogin,ac,lastlogoff,picture){
return this.http.put(`${this.config.catchApiUrl()}User/`+ id , {
id : id ,
picture : picture,
lastLogin : lastlogin ,
lastLogoff : lastlogoff ,
ac: ac
},{
headers : this.header,
withCredentials : true
})
}
Run Code Online (Sandbox Code Playgroud)
auth.component.ts :
constructor(
private authService : AuthenticationService
) { }
loginToApplication(username :string){
this.authService.updateUser(e["id"],lastLogin,e["ac"],e["lastLogoff"],e["picture"]).subscribe(
console.log("enter"))
}
Run Code Online (Sandbox Code Playgroud)
.Net Core API 更新用户控制器:
[AllowAnonymous] // Even if I do this it doesn't work
[HttpPut("{id}")]
public …Run Code Online (Sandbox Code Playgroud) 我在 .Net Core Web Api 和 Angular 应用程序上工作。我创建了一个控制器,它将图像链接到数据库中的项目:
[HttpPut("[Action]/{id}")]
public async Task<ActionResult<Item>> LinkItemToIcon(int id, IFormFile file)
{
var items = await _context.Items.FirstOrDefaultAsync(t => t.Id == id);
if (items == null)
{
return BadRequest("item null");
}
if (file.Length <= 0)
{
return BadRequest("fileEmpty");
}
using (var memoryStream = new MemoryStream())
{
await file.CopyToAsync(memoryStream);
Item item = new Item() { Id = items.Id, Icon = memoryStream.ToArray() };
_context.Entry(items).CurrentValues.SetValues(item);
_context.SaveChanges();
return Ok(file);
}
}
Run Code Online (Sandbox Code Playgroud)
它在 Postman 中运行良好,但是当我想使用控制器时,出现错误:
标头:HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, headers: …
我里面有一个文件dGVzdA ==,dGVzdA ==是单词test convert in byte []。
之后,我想让这个词再次进行字符串测试,所以我这样做:
[HttpPost("[Action]")]
public async Task<IActionResult> ExtractLicenseData(IFormFile file){
string fileContents ;
using (var stream = file.OpenReadStream())
{
using (var reader = new StreamReader(stream))
{
fileContents = await reader.ReadToEndAsync();
}
}
string test = Encoding.ASCII.GetString(fileContents); // error
return BadRequest(test);
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试做时,string test = Encoding.ASCII.GetString(fileContents);我出现了错误:
无法从“字符串”转换为“字节[]”
恢复 :
我有我的字符串dGVzdA ==我想最终在原始字符串测试中将其转换。
/!\要从测试转到dGVzdA ==,请执行此操作Encoding.ASCII.GetBytes("test")。