Google Cloud Storage Java API를 사용하여 Google Cloud Storage에 파일을 업로드하고 md5 또는 업로드하기 전에 파일에 대한 crc32c checksum/hash.잘못된 요청 400 개 오류 발생 파일에 대해 생성 된 MD5 또는 CRC32C 체크섬을 사용하여 Google Cloud Storage에 파일 업로드 시도 중
나는 (두 MD5 및 crc32c 해시에 대한) 아래 것과 유사한 오류가 점점 계속하고 내가 잘못 뭐하는 거지 아무 생각이 없다 :
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Provided CRC32C \"qtQiXA==\" doesn't match calculated CRC32C \"AAAAAA==\"."
}
],
"code": 400,
"message": "Provided CRC32C \"qtQiXA==\" doesn't match calculated CRC32C \"AAAAAA==\"."
}
}
파일 업로드가없는 MD5 또는 crc32c 체크섬 값 경우 작동을 BlobInfo에 설정됩니다. 내가 파일 방울을 업로드 할 WriteChannel를 사용하기 전에 달성하기 위해 노력하고있는 무슨의 코드는 다음과 같습니다 나열되어 구글 구아바 해싱 API를 사용하여
내가 파일 crc32c을 생성하기 위해 사용하고// Upload a blob to the identified bucket and use md5 or crc32c checksum
BlobId blobId = BlobId.of(storageBucketName, sourceEvent.getFileName());
BlobInfo blobInfo = null;
Storage.BlobWriteOption blobWriteOption = null;
if(sourceEvent.getFileHash() != null && sourceEvent.getFileHashType() == FileIntegrityCheckType.CRC32C.getCheckType()) {
blobInfo = BlobInfo.newBuilder(blobId).setStorageClass(
GoogleCloudStorageClass.getStorageClass(storageClass)
).setCrc32c(sourceEvent.getFileHash()).build();
blobWriteOption = Storage.BlobWriteOption.crc32cMatch();
} else if(sourceEvent.getFileHash() != null && sourceEvent.getFileHashType() == FileIntegrityCheckType.MD5.getCheckType()) {
blobInfo = BlobInfo.newBuilder(blobId).setStorageClass(
GoogleCloudStorageClass.getStorageClass(storageClass)
).setMd5(sourceEvent.getFileHash()).build();
blobWriteOption = Storage.BlobWriteOption.md5Match();
} else {
blobInfo = BlobInfo.newBuilder(blobId).setStorageClass(
GoogleCloudStorageClass.getStorageClass(storageClass)).build();
}
방법 및 MD5 해시를 아래 :
private byte[] generateCrc32CheckSum(Path file) {
byte[] crc32CheckSum = new byte[0];
if(file != null) {
byte[] buffer = new byte[SysConstants.FILE_READ_BUFFER_SIZE];
int limit = -1;
HashFunction crc32cHashFunc = Hashing.crc32c();
Hasher crc32cHasher = crc32cHashFunc.newHasher();
try (FileInputStream fis = new FileInputStream(file.toFile())) {
while ((limit = fis.read(buffer)) > 0) {
crc32cHasher.putBytes(buffer, 0, limit);
}
// crc32CheckSum = crc32cHasher.hash().asBytes();
crc32CheckSum = Ints.toByteArray(crc32cHasher.hash().asInt());
} catch (IOException e) {
e.printStackTrace();
}
}
return crc32CheckSum;
}
private byte[] generateMd5Hash(Path file) {
byte[] md5Hash = new byte[0];
if(file != null) {
byte[] buffer = new byte[SysConstants.FILE_READ_BUFFER_SIZE];
int limit = -1;
HashFunction md5HashFunc = Hashing.md5();
Hasher md5Hasher = md5HashFunc.newHasher();
try (FileInputStream fis = new FileInputStream(file.toFile())) {
while ((limit = fis.read(buffer)) > 0) {
md5Hasher.putBytes(buffer, 0, limit);
}
md5Hash = md5Hasher.hash().asBytes();
} catch (IOException e) {
e.printStackTrace();
}
}
return md5Hash;
}
내가 다음 방법에서 Base64 인코딩 할
: 내가 잘못
public void queueFileWithSizeAndIntegrityCheckToken(SourceEvent sourceEvent, FileTransferStatus queuedStatus) {
if(isFileTransferReady(sourceEvent)) {
String fileName = sourceEvent.getFileName();
Path filePath = Paths.get(fileName);
if(filePath != null) {
long fileSize = filePath.toFile().length();
if(fileSize > 0) {
sourceEvent.setFileSize(fileSize);
if (isIntegrityCheckEnabled) {
if (integrityCheckType.equalsIgnoreCase(FileIntegrityCheckType.CRC32C.getIntegrityCheckTokenType())) {
byte[] crc32CheckSum = generateCrc32CheckSum(filePath);
if(crc32CheckSum.length > 0) {
sourceEvent.setFileHash(BaseEncoding.base64().encode(crc32CheckSum));
sourceEvent.setFileHashType(FileIntegrityCheckType.CRC32C.getCheckType());
}
} else if (integrityCheckType.equalsIgnoreCase(FileIntegrityCheckType.MD5.getIntegrityCheckTokenType())) {
byte[] md5Token = generateMd5Hash(filePath);
if(md5Token.length > 0) {
sourceEvent.setFileHash(BaseEncoding.base64().encode(md5Token));
sourceEvent.setFileHashType(FileIntegrityCheckType.MD5.getCheckType());
}
}
}
fileTransferLogService.updateSourceEventStatus(sourceEvent,
queuedStatus);
}
}
}
}
누군가가 친절하게 검토하고 알려 수를하고있는 중이 야? 고맙습니다.
대답이 없지만'AAAAAA =='는 빈 파일의 CRC32C입니다. 그게 도움이 되니? 내 말은, 다른 어떤 것도 빈 파일을 업로드하도록 할 수 있습니까? –
빈 파일을 업로드 할 의문이 있습니다. BlobInfo 객체에 crc32c 또는 md5 해시를 설정하지 않으면 파일이 정상적으로 업로드됩니다. 해시 유형과 값 중 하나를 설정할 때만 문제가 있습니다. – Doug