从angularjs上的web api接收zip文件时,获取错误'压缩(压缩)文件夹无效' [英] Getting error 'the compressed(zipped) folder is invalid' while receiving zip file from web api on angularjs
本文介绍了从angularjs上的web api接收zip文件时,获取错误'压缩(压缩)文件夹无效'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取错误'在angularjs上从web api接收zip文件时,压缩(压缩)文件夹无效'。我正在web api创建一个zip文件并将文件发送到angularjs POST方法调用。
角度解决方案接收数据但使用BLOB对象并保存它保存为1 KB文件和该文件已损坏。
我尝试过:
Web Api代码:
Getting error 'The compressed(zipped) folder is invalid' while receiving zip file from web api on angularjs. I am creating a zip file at web api and sending the file to angularjs POST method call.
The angular solution receives the data but on using a BLOB object and saving it it is saved as 1 KB file and the file is corrupted.
What I have tried:
Web Api code:
[HttpPost]
[ODataRoute("DownloadGalleryzipfile")]
public IHttpActionResult DownloadGalleryzipfile(string type, string galleryIds)
{
appLogService.WriteLog("MapService.Service", "MapServiceController", "DownloadGalleryzipfile", "DownloadGalleryzipfile method is executing");
List<int> lstIds = galleryIds.Split(',').ToList().ConvertAll<int>(Convert.ToInt32); ;
var result = this.mapServiceDomain.GetSpecificGalleryImagesVideos(type, lstIds.ToArray());
if (result!= null & result.Count>0)
{
using (ZipFile zip = new ZipFile())
{
foreach(var galleryDetail in result)
{
zip.AddEntry(galleryDetail.Name, Convert.FromBase64String(galleryDetail.ImageStream));//Zip file inside filename
}
var pushStreamContent = new PushStreamContent((stream, content, context) =>
{
zip.Save(stream);
stream.Close();
}, "application/zip");
HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = pushStreamContent
};
httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = result.FirstOrDefault().CityNm+ type + "Gallery.zip"
};
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
httpResponseMessage.Headers.AcceptRanges.Add("bytes");
ResponseMessageResult responseMessageResult = ResponseMessage(httpResponseMessage);
return responseMessageResult;
}
}
else
{
HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.ExpectationFailed);
ResponseMessageResult responseMessageResult = ResponseMessage(httpResponseMessage);
return responseMessageResult;
}
}
Angular side ajax call;
Angular side ajax call;
$http({
method: 'POST',
url: dcsoConfig.DownloadGalleryzipfile + 'Images&galleryIds=' + downloadImageIds,
responseType: 'arraybuffer',
ContentType: 'application/json',
Accept: 'application/zip',
cache: false
}).then(
function(data, status, headers, config) {
var a = document.createElement('a');
var blob = new Blob([data], { 'type': "application/zip" });
a.href = URL.createObjectURL(blob);
a.download = "filename.zip";
a.click();
});
推荐答案
http({
方法:'POST',
url:dcsoConfig.DownloadGalleryzipfile +'Images& galleryIds ='+ downloadImageIds,
responseType:'arraybuffer',
ContentType:'application / json',
接受:'application / zip',
cache:false
})。then(
function(data,status,headers,config){
var a = document.createElement('a');
var blob = new Blob([data],{'type':application / zip});
a.href = URL.createObjectURL(blob);
a.download =filename.zip;
a.click();
});
http({ method: 'POST', url: dcsoConfig.DownloadGalleryzipfile + 'Images&galleryIds=' + downloadImageIds, responseType: 'arraybuffer', ContentType: 'application/json', Accept: 'application/zip', cache: false }).then( function(data, status, headers, config) { var a = document.createElement('a'); var blob = new Blob([data], { 'type': "application/zip" }); a.href = URL.createObjectURL(blob); a.download = "filename.zip"; a.click(); });
这篇关于从angularjs上的web api接收zip文件时,获取错误'压缩(压缩)文件夹无效'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文