Comments (5)
New methods of Blob are suggested:
public void uploadFrom(Path path, BlobWriteOption... options) {...}
public void uploadFrom(Path path, int chunkSize, BlobWriteOption... options) {...}
public void uploadFrom(InputStream input, BlobWriteOption... options) {...}
/**
* Uploads the given content to this blob using specified blob write options and the provided
* chunk size. The default chunk size is 2 MB. Larger chunk sizes may improve the upload
* performance but require more memory. It could cause OutOfMemoryError or add significant garbage
* collection overhead. Chunk sizes which are less than 256 KB are not allowed, they will be
* treated as 256 KB.
*
* @param input content to be uploaded
* @param chunkSize the minimum size that will be written by a single RPC.
* @param options blob write options
* @throws StorageException upon failure
*/
public void uploadFrom(InputStream input, int chunkSize, BlobWriteOption... options) {
chunkSize = Math.max(chunkSize, 262144); // adjust with MinChunkSize of BaseWriteChannel
try (WriteChannel writer = storage.writer(this, options)) {
writer.setChunkSize(chunkSize);
byte[] buffer = new byte[chunkSize];
int length;
while ((length = input.read(buffer)) >= 0) {
writer.write(ByteBuffer.wrap(buffer, 0, length));
}
} catch (IOException e) {
throw new StorageException(e);
}
}
from java-storage.
The following extension to the Blob class is proposed:
public Blob uploadFrom(Path path, BlobWriteOption... options)
public Blob uploadFrom(InputStream input, BlobWriteOption... options)
/**
* Uploads the given content to the storage using specified write channel and the given
* buffer size. The default buffer size is 15 MB. Larger buffer sizes may improve the upload
* performance but require more memory. It could cause OutOfMemoryError or add significant garbage
* collection overhead. Buffer sizes which are less than 256 KB are not allowed, they will be
* treated as 256 KB.
*
* <p>Note that this method does not close neither InputStream nor WriterChannel</p>
*
* <p>Example of uploading:
*
* <pre>{@code
* Path file = Paths.get("humongous.file");
* try (InputStream input = Files.newInputStream(file); WriteChannel writer = storage.writer(blobInfo)) {
* Blob.upload(input, writer, 150 * 1024 * 1024);
* }
*
* @param input content to be uploaded
* @param writer channel
* @param bufferSize size of the buffer to read from input and send over writer
*/
public static void upload(InputStream input, WriteChannel writer, int bufferSize)
from java-storage.
Similar extension to the Storage interface is planned to be proposed with a separate PR
from java-storage.
fix was reverted by #190
from java-storage.
#214 fixes this issue as well
from java-storage.
Related Issues (20)
- com.example.storage.bucket.PrintPubSubNotificationTest: testPrintBucketPubSubNotification failed HOT 2
- Warning: a recent release failed HOT 2
- Add support for Autoclass v2.1 HOT 1
- grpc compatibility with storage 2.27.x HOT 3
- Google Cloud Storage: unexpected exception after successfully writing to a Google Cloud Storage object HOT 2
- grpc compatibility issue 2.27.1 HOT 9
- GCP cloud storage downloaded file corruption HOT 4
- Improve Virtual Thread compatibility
- Unable to initiate resumable uploads from java sdk: Cloud storage v2 API. HOT 4
- Unable to Get or Refresh access token from Google Credentials instance in java sdk HOT 1
- Novel transient error introduced between 2.27.1 and 2.30.1? HOT 5
- Add Support for includeFolders option in ListObjects HOT 3
- Fix retry logic on SSL Connection Reset errors and Error writing request body to server HOT 1
- storage: memory leak while writing to GCS bucket HOT 6
- Uploading files to GCS via WriteChannel cause the memory to increase - memory not released HOT 3
- Use opentelemetry for tracing google-cloud-storage client calls
- Storage.writer(...) breaks the idea of 'generation' HOT 2
- Support for Storage Control Quickstart
- Issue with GCS matchGlob method HOT 3
- Jqwik Usage Survey HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-storage.