-
Notifications
You must be signed in to change notification settings - Fork 77
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
feat: auto content-type on blob creation #338
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9795972
feat: auto content-type on blob creation
dmitry-fa a5da742
feat: auto content-type on blob creation
dmitry-fa 6320364
feat: auto content-type on blob creation
dmitry-fa 3cc79cb
feat: auto content-type on blob creation
dmitry-fa 15fe56c
feat: auto content-type on blob creation
dmitry-fa 6b7f98b
feat: auto content-type on blob creation
dmitry-fa 6b14a3e
merge
dmitry-fa 736ed2e
detection content type is made optional
dmitry-fa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,11 +77,12 @@ | |
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.math.BigInteger; | ||
import java.net.FileNameMap; | ||
import java.net.URLConnection; | ||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.activation.MimetypesFileTypeMap; | ||
|
||
public class HttpStorageRpc implements StorageRpc { | ||
public static final String DEFAULT_PROJECTION = "full"; | ||
|
@@ -99,7 +100,7 @@ public class HttpStorageRpc implements StorageRpc { | |
private final HttpRequestInitializer batchRequestInitializer; | ||
|
||
private static final long MEGABYTE = 1024L * 1024L; | ||
private static final MimetypesFileTypeMap MIMETYPES_FILE_TYPE_MAP = new MimetypesFileTypeMap(); | ||
private static final FileNameMap FILE_NAME_MAP = URLConnection.getFileNameMap(); | ||
|
||
public HttpStorageRpc(StorageOptions options) { | ||
HttpTransportOptions transportOptions = (HttpTransportOptions) options.getTransportOptions(); | ||
|
@@ -376,9 +377,12 @@ public Tuple<String, Iterable<StorageObject>> list(final String bucket, Map<Opti | |
|
||
private static String detectContentType(StorageObject object) { | ||
String contentType = object.getContentType(); | ||
return contentType != null | ||
? contentType | ||
: MIMETYPES_FILE_TYPE_MAP.getContentType(object.getName().toLowerCase()); | ||
if (contentType != null) { | ||
return contentType; | ||
} | ||
return firstNonNull( | ||
FILE_NAME_MAP.getContentTypeFor(object.getName().toLowerCase()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. toLowerCase always should have a locale There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
"application/octet-stream"); | ||
} | ||
|
||
private static Function<String, StorageObject> objectFromPrefix(final String bucket) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an optional feature that's disabled by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about making this feature optional, but I didn't find an appropriate place to store this setting. It could be a property of a project/client/bucket/object.
I only found: https://cloud.google.com/storage/docs/metadata#content-type
which states:
If the Content-Type is not specified by the uploader and cannot be determined, it is set to application/octet-stream or application/x-www-form-urlencoded, depending on how you uploaded the object.
If I read this correctly, the Storage should attempt to determine the content type if not explicitly set, so this feature should be on by default.
BTW, right now the content type of blobs created with Storage.create() methods is
null
, but should beapplication/octet-stream
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storage doesn't provide contentType detection in the API.
If contentType is set at creation then
application/octet-stream
is used.Please make this optional otherwise it's a behavior change not originally intended on uploads with the Java client.