我正在使用這個指令(ng--file-upload)來上傳圖片。
我需要包含圖像文件到POST
到ASP.NET Web API,但我沒有任何成功。
這是我的服務器上的方法:無法上傳圖片文件從ng-file-upload到web api
public async Task<HttpResponseMessage> SaveData([FromBody]PostModel data)
當我發佈的數據(從JS角)的所有資料都在這兒,除了上傳文件:
$http({
method: 'POST',
url: path,
data: data,
file: photoFile
}).then(function...
我試圖把它的數據還,但它始終爲空。
如何發佈並獲取Web api上的圖像文件?
正如我得到的迴應:
"Invalid 'HttpContent' instance provided. It does not have a content type header starting with 'multipart/'.
Parameter name: content"
在此行中:
var provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);
var data = {
"Username": $scope.username,
transformRequest: angular.identity,
headers: { 'Content-Type': undefined }
};
var fd = new FormData();
fd.append('file', $scope.photoFile);
$http({
method: 'POST',
url: 'path', fd,
data: data
}).the
您可以使用'Upload.upload()'服務發送文件。閱讀文檔。 – danial