Conversation

JesseLovelace

Adds options for creating a blob ID from a storage url and vice versa. Fixes #868

@JesseLovelaceJesseLovelace requested review from BenWhitehead and a team June 18, 2021 00:37
@product-auto-labelproduct-auto-label bot added the api: storageIssues related to the googleapis/java-storage API.label Jun 18, 2021
@google-clagoogle-cla bot added the cla: yesThis human has signed the Contributor License Agreement.label Jun 18, 2021
@JesseLovelaceJesseLovelace changed the title Add from and to storage url options for BlobId feat: Add from and to storage url options for BlobId Jun 18, 2021
*
* @param storageUrl the Storage url to create the blob from
*/
public static BlobId fromStorageUrl(String storageUrl) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe fromGsutilUri instead of storage? To my knowledge, there are many different types of storage URLs

  • https://storage.googleapis.com/bucket/blob
  • https://storage.cloud.google.com/bucket/blob

In the cloud console these format of URI are labeled gsutil URI
image

Comment on lines 132 to 133
String bucketName = storageUrl.split("/")[2];
String blobName = storageUrl.split(bucketName + "/")[1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly simplify string allocation and traversal?

Suggested change
String bucketName = storageUrl.split("/")[2];
String blobName = storageUrl.split(bucketName + "/")[1];
int blobNameStartIndex = storageUrl.indexOf('/', 5);
String bucketName = storageUrl.substring(5, blobNameStartIndex);
String blobName = storageUrl.substring(blobNameStartIndex);

@JesseLovelaceJesseLovelace merged commit 1876a58 into master Jun 24, 2021
@JesseLovelaceJesseLovelace deleted the blobtofromurl branch June 24, 2021 22:07
@release-pleaserelease-please bot mentioned this pull request Aug 10, 2022
Sign up for free to join this conversation on . Already have an account? Sign in to comment
api: storageIssues related to the googleapis/java-storage API.cla: yesThis human has signed the Contributor License Agreement.
None yet

Successfully merging this pull request may close these issues.

Add fromStorageUrl and toStorageUrl methods to BlobId