Загруженный PDF в Google Cloud Storage всегда показывает пустую страницу - PullRequest
2 голосов
/ 21 ноября 2019

Я собираюсь загрузить файл CSV или PDF в Google Cloud Storage, используя этот код:

public static String uploadFile(String fileName, String fileLocation, final String bucketName) throws IOException {
      DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
      DateTime dt = DateTime.now(DateTimeZone.UTC);
      String dtString = dt.toString(dtf);
      fileName += dtString;

      // The InputStream is closed by default, so we don't need to close it here
      // Read InputStream into a ByteArrayOutputStream.

      File file = new File(fileLocation);

      InputStream is = new FileInputStream(file);
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      byte[] readBuf = new byte[4096];
      while (is.available() > 0) {
        int bytesRead = is.read(readBuf);
        os.write(readBuf, 0, bytesRead);
      }

      is.close();

      // Convert ByteArrayOutputStream into byte[]
      BlobInfo blobInfo =
          storage.create(
              BlobInfo
                  .newBuilder(bucketName, fileName)
                  // Modify access list to allow all users with link to read file
                  .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
                  .build(),
              os.toByteArray());
      // return the public download link
      return blobInfo.getMediaLink();
    }

Когда я загружаю загруженный файл, если это файл CSV, это нормально, нокогда я загружаю файл PDF, он всегда показывает пустую страницу. И на самой консоли также отображается пустая страница.

...