11using System ;
22using System . Drawing ;
33using System . IO ;
4- using System . IO . Compression ;
54using System . Net ;
65using System . Net . Http ;
76using System . Net . Http . Headers ;
1211using eFormApi . BasePn . Infrastructure . Helpers ;
1312using eFormApi . BasePn . Infrastructure . Messages ;
1413using eFormApi . BasePn . Infrastructure . Models . API ;
14+ using Ionic . Zip ;
1515
1616namespace eFormAPI . Web . Controllers
1717{
@@ -237,14 +237,11 @@ public HttpResponseMessage UploadEformZip()
237237 {
238238 return Request . CreateResponse ( HttpStatusCode . BadRequest , "Folder error" ) ;
239239 }
240- if ( ! Directory . Exists ( saveFolder ) )
241- {
242- Directory . CreateDirectory ( saveFolder ) ;
243- }
244- if ( ! Directory . Exists ( zipArchiveFolder ) )
245- {
246- Directory . CreateDirectory ( zipArchiveFolder ) ;
247- }
240+
241+ Directory . CreateDirectory ( saveFolder ) ;
242+
243+ Directory . CreateDirectory ( zipArchiveFolder ) ;
244+
248245 var files = HttpContext . Current . Request . Files ;
249246 if ( files . Count > 0 )
250247 {
@@ -253,22 +250,26 @@ public HttpResponseMessage UploadEformZip()
253250 {
254251 var filePath = Path . Combine ( zipArchiveFolder , Path . GetFileName ( httpPostedFile . FileName ) ) ;
255252 var extractPath = Path . Combine ( saveFolder ) ;
256- if ( ! File . Exists ( filePath ) )
253+ if ( File . Exists ( filePath ) )
257254 {
258- httpPostedFile . SaveAs ( filePath ) ;
255+ File . Delete ( filePath ) ;
259256 }
257+ httpPostedFile . SaveAs ( filePath ) ;
260258 if ( File . Exists ( filePath ) )
261259 {
262- if ( ! Directory . Exists ( extractPath ) )
263- {
264- Directory . CreateDirectory ( extractPath ) ;
265- }
266- else
260+ Directory . CreateDirectory ( extractPath ) ;
261+ FoldersHelper . ClearFolder ( extractPath ) ;
262+
263+ using ( var zip = ZipFile . Read ( filePath ) )
267264 {
268- FoldersHelper . ClearFolder ( extractPath ) ;
265+ foreach ( var entry in zip . Entries )
266+ {
267+ if ( entry . FileName . Contains ( ".png" ) || entry . FileName . Contains ( "jrxml" ) )
268+ {
269+ entry . Extract ( extractPath ) ;
270+ }
271+ }
269272 }
270-
271- ZipFile . ExtractToDirectory ( filePath , extractPath ) ;
272273 File . Delete ( filePath ) ;
273274 _coreHelper . bus . SendLocal ( new GenerateJasperFiles ( templateId ) ) ;
274275
@@ -278,10 +279,12 @@ public HttpResponseMessage UploadEformZip()
278279 }
279280 return Request . CreateResponse ( HttpStatusCode . BadRequest , LocaleHelper . GetString ( "InvalidRequest" ) ) ;
280281 }
281- catch ( Exception )
282+ catch ( Exception ex )
282283 {
283284 return new HttpResponseMessage ( HttpStatusCode . InternalServerError ) ;
284285 }
285286 }
286287 }
288+
289+
287290}
0 commit comments