有两个方案
1 ,通过 exif 访问图片
2,操作元数据(关于资源的信息较少)
一,通过 exif 访问图片
主要是通过?x-oss-process=image/info
来获取图片信息,
还有很多其他参数可以选择。
示例
获取不包含EXIF信息的原图示例
http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/info
{ "FileSize": {"value": "21839"}, "Format": {"value": "jpg"}, "ImageHeight": {"value": "267"}, "ImageWidth": {"value": "400"} }
获取包含EXIF信息的原图示例
http://image-demo.oss-cn-hangzhou.aliyuncs.com/f.jpg?x-oss-process=image/info
{ "Compression": {"value": "6"}, "DateTime": {"value": "2015:02:11 15:38:27"}, "ExifTag": {"value": "2212"}, "FileSize": {"value": "23471"}, "Format": {"value": "jpg"}, "GPSLatitude": {"value": "0deg "}, "GPSLatitudeRef": {"value": "North"}, "GPSLongitude": {"value": "0deg "}, "GPSLongitudeRef": {"value": "East"}, "GPSMapDatum": {"value": "WGS-84"}, "GPSTag": {"value": "4292"}, "GPSVersionID": {"value": "2 2 0 0"}, "ImageHeight": {"value": "333"}, "ImageWidth": {"value": "424"}, "JPEGInterchangeFormat": {"value": "4518"}, "JPEGInterchangeFormatLength": {"value": "3232"}, "Orientation": {"value": "7"}, "ResolutionUnit": {"value": "2"}, "Software": {"value": "Microsoft Windows Photo Viewer 6.1.7600.16385"}, "XResolution": {"value": "96/1"}, "YResolution": {"value": "96/1"}}
二,获取元数据
oss 文档:https://help.aliyun.com/document_detail/84840.html
以下代码用于获取文件元信息:
// Endpoint以杭州为例,其它Region请按实际情况填写。 String endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。 String accessKeyId = "<yourAccessKeyId>"; String accessKeySecret = "<yourAccessKeySecret>"; // 创建OSSClient实例。 OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); // 获取文件的部分元信息。 SimplifiedObjectMeta objectMeta = ossClient.getSimplifiedObjectMeta("<yourBucketName>", "<yourObjectName>"); System.out.println(objectMeta.getSize()); System.out.println(objectMeta.getETag()); System.out.println(objectMeta.getLastModified()); // 获取文件的全部元信息。 ObjectMetadata metadata = ossClient.getObjectMetadata("<yourBucketName>", "<yourObjectName>"); System.out.println(metadata.getContentType()); System.out.println(metadata.getLastModified()); System.out.println(metadata.getExpirationTime()); // 关闭OSSClient。 ossClient.shutdown();