gpt4 book ai didi

java - Google App Engine 中 blobstore 对象的 1MB 配额限制?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:14:29 25 4
gpt4 key购买 nike

我正在使用 App Engine (version 1.4.3) direct write the blobstore为了保存图像。当我尝试存储大于 1MB 的图像时,出现以下异常

com.google.apphosting.api.ApiProxy$RequestTooLargeException: The request to API call datastore_v3.Put() was too large.

我认为 limit for each object is 2GB

这是存储图片的Java代码

private void putInBlobStore(final String mimeType, final byte[] data) throws IOException {
final FileService fileService = FileServiceFactory.getFileService();
final AppEngineFile file = fileService.createNewBlobFile(mimeType);
final FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
writeChannel.write(ByteBuffer.wrap(data));
writeChannel.closeFinally();
}

最佳答案

下面是我读写大文件的方式:

public byte[] readImageData(BlobKey blobKey, long blobSize) {
BlobstoreService blobStoreService = BlobstoreServiceFactory
.getBlobstoreService();
byte[] allTheBytes = new byte[0];
long amountLeftToRead = blobSize;
long startIndex = 0;
while (amountLeftToRead > 0) {
long amountToReadNow = Math.min(
BlobstoreService.MAX_BLOB_FETCH_SIZE - 1, amountLeftToRead);

byte[] chunkOfBytes = blobStoreService.fetchData(blobKey,
startIndex, startIndex + amountToReadNow - 1);

allTheBytes = ArrayUtils.addAll(allTheBytes, chunkOfBytes);

amountLeftToRead -= amountToReadNow;
startIndex += amountToReadNow;
}

return allTheBytes;
}

public BlobKey writeImageData(byte[] bytes) throws IOException {
FileService fileService = FileServiceFactory.getFileService();

AppEngineFile file = fileService.createNewBlobFile("image/jpeg");
boolean lock = true;
FileWriteChannel writeChannel = fileService
.openWriteChannel(file, lock);

writeChannel.write(ByteBuffer.wrap(bytes));
writeChannel.closeFinally();

return fileService.getBlobKey(file);
}

关于java - Google App Engine 中 blobstore 对象的 1MB 配额限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5522804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com