Advertisement
retnet

direct link from google drive

May 10th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // gdrive link must be share
  2. ###########
  3. public static String getFinalUrl(String pdfUrl) {
  4. String documentId = getDocumentId(pdfUrl);
  5. pdfUrl = "https://drive.google.com/uc?export=download&id=" + documentId;
  6. return pdfUrl;
  7. }
  8. public static String getDocumentId(String pdfUrl) {
  9. int beginIndex = "https://drive.google.com/file/d/".length();
  10. int endIndex = pdfUrl.lastIndexOf('/');
  11. if (endIndex < 0) {
  12. endIndex = pdfUrl.length();
  13. }
  14. String documentId;
  15. try {
  16. documentId = pdfUrl.substring(beginIndex, endIndex);
  17. } catch (StringIndexOutOfBoundsException e) {
  18. e.printStackTrace();
  19. return "";
  20. }
  21. return documentId;
  22. }
  23. ===================
  24. usage =
  25. getFinalUrl("https://drive.google.com/file/d/1yqZtxX3YYpVOkqzvukg4-hGA6cwac5oJ/view?usp=share_link");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement