我正在尝试与Amazon CloudFront集成的Spring Web服务。要创建signed url
,CloudFront API需要一个包含私钥的java.io.File
对象。该文件采用.pem
格式,API如下所示:
String signedUrl = CloudFrontUrlSigner.getSignedURLWithCannedPolicy(
Protocol.https,
distributionDomainName,
cloudFrontPrivateKeyFile, // KEY FILE
"/images/img.jpg",
cloudFrontKeyPairId,
expirationDate);
如何在Spring中将文件加载到内存中?我找到的所有示例都是从资源加载文件,如下所示:
final Resource fileResource =
resourceLoader.getResource("classpath:config/pk-mykey.pem");
cloudFrontPrivateKeyFile = fileResource.getFile()
但是,此代码抛出异常:
class path resource [config/pk-mykey.pem] cannot be resolved to absolute file path because it does not reside in the file system: