How to get file extension from google drive direct download link?

问题: I have given a URI which is from google drive direct download link of a image, and I want to find the file extension of the file that is returned, what do I have to do in J...

问题:

I have given a URI which is from google drive direct download link of a image, and I want to find the file extension of the file that is returned, what do I have to do in Java.

For example Link will be like: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:-

fileName--/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k fileName-extrect from link-/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k


回答1:

For your example URL there is a redirect to a different URL, but a request to that URL returns a response with the header content-type. For your example it is image/jpeg.

  • 发表于 2019-03-29 14:14
  • 阅读 ( 259 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除