【问题标题】:How to get file extension from google drive direct download link?如何从谷歌驱动器直接下载链接获取文件扩展名?
【发布时间】:2019-08-18 21:55:01
【问题描述】:

我已经给出了一个来自谷歌驱动器直接下载图像链接的 URI,我想找到返回的文件的文件扩展名,我必须在 Java 中做什么。

例如链接如下:https://drive.google.com/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k

`
public static String saveImage(String imageUrl, String playlist) throws 
IOException {
    URL url = new URL(imageUrl);
    String fileName = url.getFile();
    System.out.println(fileName);
        String destName 
="./figures"+fileName.substring(fileName.lastIndexOf("/"));
String destName = "../imgUpload/"+playlist;System.out.println(destName);
InputStream is = url.openStream();System.out.println("is- 
1"+is);OutputStream os = new FileOutputStream(destName);
System.out.println("is"+is);
byte[] b = new byte[2048];int length;
while ((length = is.read(b)) != -1) {
os.write(b, 0, length);
    }
    is.close();
    os.close();
    return destName;
}
`

O/P:-

文件名--/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k 文件名-从链接中提取-/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k

【问题讨论】:

    标签: java file-upload jersey image-uploading fileinputstream


    【解决方案1】:

    对于您的示例 URL,有一个重定向到不同的 URL,但对该 URL 的请求会返回带有标头 content-type 的响应。对于您的示例,它是image/jpeg

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-17
      • 2017-08-26
      相关资源
      最近更新 更多