title: Image, Pdf download not working in Java Rest Api
body: <p>Im trying to download the image and pdf with the below code</p>
  <pre><code>        File createdFile = new File(&quot;logs/decryptedDocs&quot;+filename);
          Path path = Paths.get(createdFile.getAbsolutePath());
          logger.info(&quot;Path is..{}&quot;,path.toUri());
          Resource resource = new UrlResource(path.toUri());
          headers.add(&quot;Content-Disposition&quot;, &quot;attachment;filename=&quot;+resource.getFilename());
  
          // Try to determine file's content type
          String contentType = null;
          try {
              contentType = httpServletRequest.getServletContext().getMimeType(resource.getFile().getAbsolutePath());
          } catch (IOException ex) {
              logger.info(&quot;Could not determine file type.&quot;);
          }
  
          // Fallback to the default content type if type could not be determined
          if(contentType == null) {
              contentType = &quot;application/octet-stream&quot;;
          }
          logger.info(&quot;ContentType is..{}&quot;,contentType);
          return ResponseEntity.ok()
                  .headers(headers)
                  .contentLength(createdFile.length())
                  .contentType(MediaType.parseMediaType(contentType))
                  .body(resource);
  </code></pre>
  <p>In my local it is working and in postman when I checked image was visible but couldn't download directly in postman also but when I try to hit the API from front end, the image is visible in the preview section but getting some error in the response like json parser exception. front end technology used is AngularJs.</p>
  <p>please help me on this.</p>