1、run configuration 添加vm参数:
-Dhttps.proxy=http://googleapis-dev.gcp.cloud.uk.hsbc:3128
-Dhttps.proxyHost=googleapis-dev.gcp.cloud.uk.hsbc
-Dhttps.proxyPort=3128
2、
Storage.BlobTargetOption precondition = Storage.BlobTargetOption.doesNotExist();
File cert = new File(gcsProperties.getCertPath());
if (!cert.exists()) {
log.error("cert json is not exist");
}
Storage storage =StorageOptions.newBuilder()
.setProjectId(gcsProperties.getProjectId())
.setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream(gcsProperties.getCertPath())))
.build().getService();
BlobId blobId = BlobId.of(gcsProperties.getBucketName(), objectName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
//上传文件到GCP
Blob result = storage.create(blobInfo, dataBytes, precondition);
@Data标签:gcsProperties,java,String,Storage,private,cert,歌云,Dhttps,上传 From: https://www.cnblogs.com/ivyJ/p/17015491.html
@AllArgsConstructor
public class GcsProperties {
private String bucketName;
private String certPath;
private String projectId;
}