Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

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

Closed

Description

@niclarcipretti

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

Activity

  1. chingor13 commented on Dec 7, 2018

    @chingor13
    Contributor

    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

  2. andrey-qlogic commented on Jan 18, 2019

    @andrey-qlogic
    Contributor

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

  3. dhoard commented on Mar 12, 2019

    @dhoard

    @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.

  4. andrey-qlogic commented on Mar 14, 2019

    @andrey-qlogic
    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;
      }
  5. dhoard commented on Mar 14, 2019

    @dhoard

    @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?

  6. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Jan 7, 2020
  7. self-assigned this
    on May 20, 2020
  8. dmitry-fa commented on May 20, 2020

    @dmitry-fa
    Contributor

    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

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/java-storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions