Hier meine Client-Seite HTML (I verwendet ng Datei-Upload)ASP .NET MVC Core-Web-API-Upload-Datei zeigt Fehler mit Angular JS
<button type="file" ngf-select="uploadFileToUrl($file)"
ngf-max-size="100MB">
<!--ngf-max-height="1000"-->
Photo
</button>
Hier ist meine Client-Seite js
$scope.uploadFileToUrl = function (file) {
console.log(file) // Here console prints my file information
alert(file);
var data = new FormData();
data.append('photo', file)
$.ajax({
type: "POST",
url: "http://localhost:22475/api/FileUpload",
contentType: false,
processData: false,
data: data,
success: function (message) {
alert(message);
},
error: function() {
alert("There was error uploading files!");
}
});
}
hier ist meine Server-Seite
private IHostingEnvironment hostingEnv ;
public FileUploadController(IHostingEnvironment env)
{
this.hostingEnv = env;
}
[HttpPost]
public async Task<IActionResult> PostProfilePicture(ICollection<IFormFile> files) // Here i get file count 0 on tool tip
{
var uploads = Path.Combine(hostingEnv.WebRootPath, "uploads");
foreach (var file in files)
{
if (file.Length > 0)
{
using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
{
await file.CopyToAsync(fileStream);
}
}
}
return null;
}
hier bekomme ich Datei-Upload-Fehler i durch das Netz gesucht, alles bekam ich diesen Code, aber seine nicht funktioniert, kann jeder Hilfe und darauf hinweisen, was mache ich hier falsch.
Hallo, welchen Fehler haben Sie bei der Implementierung gesehen? – Adrian
Fehler beim Laden der Datei auf der Client-Seite –