Консоль показывает ошибку как показано на картинке и нужно от нее избавиться - PullRequest
0 голосов
/ 28 мая 2018

error image

Пожалуйста, посмотрите на изображение выше.Все, что мне нужно, это избавиться от ошибки, отображаемой на консоли.Изображение отсутствует в моем локальном каталоге, и я управлял делом в пользовательском интерфейсе, отображая какое-то другое изображение, но консоль все еще отображает эту ошибку.У кого-нибудь есть решение проблемы.Просто нужно избавиться от 404. Любая помощь будет оценена.

Java-код: API:

@GetMapping("/files/{filename:.+}")
        @ResponseBody
        public ResponseEntity<Resource> getFile(@PathVariable String filename) {
            if(filename != null) {
                Resource file = customerController.loadFile(filename);
                if(file != null) {

                    return ResponseEntity.ok()
                            .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"")
                            .body(file);

                }else {
                    return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"")
                            .body(null);

                }
            }else {
                return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"")
                        .body(null);
            }

        }


Controller:
    //customer logo image upload related api
    public Resource loadFile(String filename) {
        try {
            if(filename != null) {
                Path rootLocation = Paths.get(this.customerLogoPath);
                Path file = rootLocation.resolve(filename);
                Resource resource = new UrlResource(file.toUri());
//              System.out.println(resource);
                if (resource.exists() && resource.isReadable()) {
                    return resource;
                } else {
                    return null;
                }
            }else {
                return null;
            }

        } catch (MalformedURLException e) {
            throw new RuntimeException("FAIL!");
        }
    }

Угловая сторона кода:

Component.ts

getLogos(customer){

      let fileName = customer.customerLogoPath;
      //console.log(fileName);
      if(fileName != null && fileName != undefined && fileName != 'null'){
        //imageget
          this.http.get(this.apiEndPoint+""+fileName)
          .map( res => JSON.parse(JSON.stringify(res)))
          .catch(error => Observable.throw(error))
          .subscribe(
            image => {
              //console.log(image);
            },
            error => {
              //  console.log(error);
              if(error.status !== 404) {
                if(error.url !== null && error.url != "" && !error.url.includes('null')){

                  customer.customerLogoPath = error.url;
                  //console.log(error.url);
                }else{
                  customer.customerLogoPath  = '/assets/images/no-img.png';
                }
              }

            })
      }else{
        customer.customerLogoPath  = '/assets/images/no-img.png';
      }

  }


Component.html:


<div class="row">
                                                            <div class="box-ctn-img col-3 mx-auto text-center"  *ngIf = "customer.customerLogoPath == null && customer.customerLogoPath == undefined">
                                                                <img  src="/assets/images/no-img.png" class="rounded mx-auto d-block img-fluid">
                                                            </div>
                                                            <div class="box-ctn-img col-3 mx-auto text-center" style="margin-right: 25px;" *ngIf = "customer.customerLogoPath !== null && customer.customerLogoPath !== undefined">
                                                                    <img  src ="{{customer?.customerLogoPath}}" class="rounded mx-auto d-block img-fluid">
                                                            </div>

                                                            <div class="box-ctn-dic col-9">
                                                                <h4>[ {{customer.customerCode}} ] -
                                                                    <span>{{customer.customerName}}</span>
                                                                </h4>
                                                                <h3>
                                                                    <span>{{customer.defaultWarehouse?.name}}</span>
                                                                </h3>
                                                                <h3>
                                                                    <span>{{customer.dept?.deptName}}</span>
                                                                </h3>
                                                            </div>
                                                        </div>

Спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...