[英]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 Java. 我给了一个URI,它是从Google驱动器直接下载图像的链接,我想找到返回的文件的文件扩展名,我必须用Java做什么。
For example Link will be like: https://drive.google.com/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k 例如,链接将类似于: 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:- O / P:-
fileName--/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k fileName-extrect from link-/uc?export=download&id=0BwtDpsO0CtJZbm9iNUNMTXNTX0k fileName-/ uc?export = download&id = 0BwtDpsO0CtJZbm9iNUNMTXNTX0k fileName-从link- / uc?export = download&id = 0BwtDpsO0CtJZbm9iNUNMTXNTX0k扩展
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
. 对于您的示例URL,存在到另一个URL的重定向,但是对该URL的请求将返回带有标头
content-type
的响应。 For your example it is image/jpeg
. 对于您的示例,它是
image/jpeg
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.