Skip to content
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

Feature suggestion: auto content-type on blob creation #47

Closed
niclarcipretti opened this issue Dec 6, 2018 · 6 comments · Fixed by #338
Closed

Feature suggestion: auto content-type on blob creation #47

niclarcipretti opened this issue Dec 6, 2018 · 6 comments · Fixed by #338
Assignees
Labels
api: storage Issues related to the googleapis/java-storage API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@niclarcipretti
Copy link

What if the API saves the blob setting it's content-type automatically? I guess it would make sense at least for public blobs. Do you have an opinion on that?

Cheers

@chingor13
Copy link
Collaborator

I assume you mean that we would try to detect the file type and automatically set the Content-type metadata for the blob.

On the client side, we don't do this for developers because there are several different ways to accomplish in Java (extension, magic bytes) this with pros/cons for each method. We don't want to dictate how or whether to automatically detect the mime type so it's left to developers to do. You can do a quick Google search for "java file mime type" for several methods of detecting the mime type.

If you'd like to file a feature request against the actual backend API, you can file an issue against the service: https://issuetracker.google.com/issues/new?component=187243&template=0

@andrey-qlogic
Copy link
Contributor

@chingor13 , is there any update on this feature request?

@andrey-qlogic andrey-qlogic self-assigned this Mar 11, 2019
@dhoard
Copy link

dhoard commented Mar 12, 2019

@chingor13 thoughts on providing a setContentTypeMapping(Map<String, String> map) on StorageOptions.Builder to setup an blob name extension to content-type mapping?

It would be completely optional and shouldn't breaking any existing code.

@andrey-qlogic
Copy link
Contributor

@chingor13 , @dhoard
I would assume that we can add something like the example below
similar to https://github.com/googleapis/google-cloud-java/blob/35cc9874ce2963ca9d66aa0d584208a59154b6f3/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java#L611

public final String getContentType() {
    if (headerProvider != null) {
      for (Map.Entry<String, String> entry : headerProvider.getHeaders().entrySet()) {
        if ("content-type".equals(entry.getKey().toLowerCase())) {
          return entry.getValue();
        }
      }
    }
    return null;
  }

@dhoard
Copy link

dhoard commented Mar 14, 2019

@andrey-qlogic conceptually that might work. From an implementation standpoint, it would be better to perform a get() on the headerProvider ...

public final String getContentType() {
    String contentType = null;

    if (headerProvider != null) {
        contentType = headerProvider.get("content-type");
    }

    return contentType;
}

@chingor13 your feedback?

@chingor13 chingor13 transferred this issue from googleapis/google-cloud-java Jan 7, 2020
@chingor13 chingor13 added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Jan 7, 2020
@google-cloud-label-sync google-cloud-label-sync bot added the api: storage Issues related to the googleapis/java-storage API. label Jan 29, 2020
@dmitry-fa dmitry-fa self-assigned this May 20, 2020
@dmitry-fa
Copy link
Contributor

dmitry-fa commented May 20, 2020

Similar fix in nodejs: googleapis/nodejs-storage#1190

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/java-storage API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants