Using Java library to uploading the object to GCP https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-code-sample with the below code
public static void uploadObject(
String projectId, String bucketName, String objectName, String filePath) throws IOException {
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
BlobId blobId = BlobId.of(bucketName, objectName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
storage.create(blobInfo, Files.readAllBytes(Paths.get(filePath)));
System.out.println(
"File " + filePath + " uploaded to bucket " + bucketName + " as " + objectName);
}
The above code works well, but the content type of the image is application/octet-stream
How do I set to image/jpg
or image/png
. How can I set the meta-data before uploading