|
19 | 19 | import static com.google.common.base.Preconditions.checkArgument; |
20 | 20 | import static com.google.common.base.Preconditions.checkNotNull; |
21 | 21 |
|
| 22 | +import com.google.common.base.MoreObjects; |
22 | 23 | import com.google.gcloud.storage.Storage.BlobSourceOption; |
23 | 24 | import com.google.gcloud.storage.Storage.BlobTargetOption; |
| 25 | +import com.google.gcloud.storage.Storage.BlobWriteOption; |
24 | 26 | import com.google.gcloud.storage.Storage.BucketSourceOption; |
25 | 27 | import com.google.gcloud.storage.Storage.BucketTargetOption; |
| 28 | +import java.io.InputStream; |
26 | 29 |
|
27 | 30 | import java.util.ArrayList; |
28 | 31 | import java.util.Collections; |
@@ -172,17 +175,43 @@ public List<Blob> get(String blobName1, String blobName2, String... blobNames) { |
172 | 175 | } |
173 | 176 |
|
174 | 177 | /** |
175 | | - * Creates a new blob in this bucket. |
| 178 | + * Creates a new blob in this bucket. Direct upload is used to upload {@code content}. |
| 179 | + * For large content, {@link Blob#writer(com.google.gcloud.storage.Storage.BlobWriteOption...)} |
| 180 | + * is recommended as it uses resumable upload. MD5 and CRC32C hashes of {@code content} are |
| 181 | + * computed and used for validating transferred data. |
176 | 182 | * |
177 | 183 | * @param blob a blob name |
178 | 184 | * @param content the blob content |
| 185 | + * @param contentType the blob content type. If {@code null} then |
| 186 | + * {@value com.google.gcloud.storage.Storage#DEFAULT_CONTENT_TYPE} is used. |
179 | 187 | * @param options options for blob creation |
180 | 188 | * @return a complete blob information. |
181 | 189 | * @throws StorageException upon failure |
182 | 190 | */ |
183 | | - Blob create(String blob, byte[] content, BlobTargetOption... options) { |
184 | | - BlobId blobId = BlobId.of(info.name(), blob); |
185 | | - return new Blob(storage, storage.create(BlobInfo.builder(blobId).build(), content, options)); |
| 191 | + public Blob create(String blob, byte[] content, String contentType, BlobTargetOption... options) { |
| 192 | + BlobInfo blobInfo = BlobInfo.builder(BlobId.of(info.name(), blob)) |
| 193 | + .contentType(MoreObjects.firstNonNull(contentType, Storage.DEFAULT_CONTENT_TYPE)).build(); |
| 194 | + return new Blob(storage, storage.create(blobInfo, content, options)); |
| 195 | + } |
| 196 | + |
| 197 | + /** |
| 198 | + * Creates a new blob in this bucket. Direct upload is used to upload {@code content}. |
| 199 | + * For large content, {@link Blob#writer(com.google.gcloud.storage.Storage.BlobWriteOption...)} |
| 200 | + * is recommended as it uses resumable upload. |
| 201 | + * |
| 202 | + * @param blob a blob name |
| 203 | + * @param content the blob content as a stream |
| 204 | + * @param contentType the blob content type. If {@code null} then |
| 205 | + * {@value com.google.gcloud.storage.Storage#DEFAULT_CONTENT_TYPE} is used. |
| 206 | + * @param options options for blob creation |
| 207 | + * @return a complete blob information. |
| 208 | + * @throws StorageException upon failure |
| 209 | + */ |
| 210 | + public Blob create(String blob, InputStream content, String contentType, |
| 211 | + BlobWriteOption... options) { |
| 212 | + BlobInfo blobInfo = BlobInfo.builder(BlobId.of(info.name(), blob)) |
| 213 | + .contentType(MoreObjects.firstNonNull(contentType, Storage.DEFAULT_CONTENT_TYPE)).build(); |
| 214 | + return new Blob(storage, storage.create(blobInfo, content, options)); |
186 | 215 | } |
187 | 216 |
|
188 | 217 | /** |
|
0 commit comments