나는 이미지 업로드를 위해 asp.net 코어 및 웹 API를 사용하고 있습니다."Alternate"속성을 서버의 이미지 파일에 추가하는 방법은 무엇입니까?
클라이언트에서[Produces("application/json")]
[Route("api/Upload")]
public class UploadApiController : Controller
{
private readonly IHostingEnvironment _environment;
public UploadApiController(IHostingEnvironment environment)
{
_environment = environment;
}
[HttpPost]
public async Task Post(ICollection<IFormFile> files)
{
//...
}
}
:
// Files is an array that contains all temporary images for uploading.
let Files = [];
let image_preview = function (file) {
file['Alternate'] = 'alternate_text';
Files.push(file);
// other implements...
};
$('button#upload').click(function() {
let formData = new FormData();
for (let i = 0; i < Files.length; i++) {
formData.append('files', Files[i])
}
let xhr = new XMLHttpRequest();
xhr.open('POST', '/api/upload', true);
xhr.onload = function() {
console.log('uploading...')
};
xhr.send(formData);
});
스냅 샷 :
내 질문 : ICollection<IFormFile> files
에 새 속성 "대체"를 추가하는 방법을 감지하는 서버에서
에서 보낸 Alternate
속성 클라이언트 (formData)?