Skip to content

Java: S3 - Missing Method to receive Object Url #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Andre0711er opened this issue Sep 25, 2018 · 5 comments
Closed

Java: S3 - Missing Method to receive Object Url #255

Andre0711er opened this issue Sep 25, 2018 · 5 comments
Assignees

Comments

@Andre0711er
Copy link

Hi.

In Java S3 Client SDK Version 1.X exists a method named "getUrl" which return all informations for object url. Now i see, method doesn't exists in new SDK.

How i can solve, getting url from Object?

SDK Documentation from Java 1.X SDK:

https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3.html#getUrl-java.lang.String-java.lang.String-

greets,

Andre.

@soo-aws soo-aws self-assigned this Sep 26, 2018
@soo-aws
Copy link
Contributor

soo-aws commented Sep 26, 2018

Hi Andre,
This
https://github.com/aws/aws-sdk-java-v2/blob/7c3a05eed0a2048949561e5d44d28667800bcc84/docs/LaunchChangelog.md#411-s3-operation-migration
Covers the migration path for each of the s3 client methods. It looks like getUrl is no longer supported. Do you have a specific use case that requires the url only instead of using the getObject method to download the object?

thank you
Soo

@Andre0711er
Copy link
Author

Hi.

Thanks for your mail.
So "getObject" is not real the target.

We need to PUT Objects to S3 Storage. After that, we store URL from S3 Object into Database as relation. For that, we use the Function "getUrl" from SDK 1.X, which works great. Now, there is no real Way (which i know yet) to determine Real 100% URL from SDK.

I wrote my own simple Helper Method now for that, who check the Object via HTTP HEAD Connection, but i personally think, it's the best to use underlying Framework (S3 SDK) for this.

Thanks,

Andre.

@Bam4d
Copy link

Bam4d commented Feb 21, 2019

@AndreMarthaler can you share your code that you used to get the URL.

I'm also looking for this feature, sad it went in v2

@Andre0711er
Copy link
Author

Andre0711er commented Feb 23, 2019

Hi Chris.

I found no way to get URL from SDK. So i create it by hand.
But again, it's so sad, that there's no way via SDK. Otherwise, it's a shame, that AWS never really react on my Issue here. For me personally, it's a "forgotten" Feature. On SDK V1.X it works! WHY they take out this nice and working Feature?!

So my used method for that:

public static String getUrl(String bucketName, String path) {
    GetObjectRequest.Builder getRequestBuilder = GetObjectRequest.builder();
    getRequestBuilder.bucket(bucketName);
    getRequestBuilder.key(path);

    return getUrl(getRequestBuilder.build()).toExternalForm();
  }
public static URL getUrl(GetObjectRequest request) {
    StringBuilder urlBuilder = new StringBuilder();
    urlBuilder.append(S3_PROTOCOL);
    urlBuilder.append("://");
    urlBuilder.append(S3_HOST);
    urlBuilder.append("/");
    urlBuilder.append(request.bucket());
    urlBuilder.append("/");
    urlBuilder.append(request.key());
    URL url;
    try {
      url = new URL(urlBuilder.toString());
      return url;
    } catch (MalformedURLException e) {
      logger.error(e.toString());
    }
    return null;
  }
  • bucketName is "my bucket name"
  • path is "my uploaded path"
  • S3_PROTOCOL is "https"
  • S3_HOST is "s3.amazonaws.com"

Might be, there is a better way, but for me, it works.

Greets,

Andre.

@jschwarzwalder
Copy link
Contributor

jschwarzwalder commented Mar 24, 2019

Thank you for your request. I know the team for the AWS Java SDK are working to add more features to the Java v2.

You can formally request the feature by adding an issue on the official aws-sdk-java-v2 repository

For more information about using the S3Utilities class in v2 to get a Url, checkout issue #860.

I"m going to close this issue for now, but if you want to add a code example feel free to create a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants