diff --git a/zboxcore/sdk/chunked_upload.go b/zboxcore/sdk/chunked_upload.go index aa4b9729a..06d4cdd1d 100644 --- a/zboxcore/sdk/chunked_upload.go +++ b/zboxcore/sdk/chunked_upload.go @@ -458,6 +458,7 @@ func (su *ChunkedUpload) process() error { if chunks.isFinal { if su.fileMeta.ActualHash == "" { su.fileMeta.ActualHash, err = su.chunkReader.GetFileHash() + logger.Logger.Info("ActualHash: ", su.fileMeta.ActualHash) if err != nil { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err) @@ -611,6 +612,9 @@ func (su *ChunkedUpload) readChunks(num int) (*batchChunksData, error) { //blobber i data.fileShards[i] = append(data.fileShards[i], v) } + } else { + data.isFinal = true + break } if chunk.IsFinal { @@ -646,7 +650,10 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, wgErrors := make(chan error, len(su.blobbers)) if len(fileShards) == 0 { - return thrown.New("upload_failed", "Upload failed. No data to upload") + if !isFinal { + return thrown.New("upload_failed", "Upload failed. No data to upload") + } + fileShards = make([]blobberShards, len(su.blobbers)) } for i := su.uploadMask; !i.Equals64(0); i = i.And(zboxutil.NewUint128(1).Lsh(pos).Not()) { diff --git a/zboxcore/sdk/chunked_upload_blobber.go b/zboxcore/sdk/chunked_upload_blobber.go index 886464aff..c323549e2 100644 --- a/zboxcore/sdk/chunked_upload_blobber.go +++ b/zboxcore/sdk/chunked_upload_blobber.go @@ -53,21 +53,6 @@ func (sb *ChunkedUploadBlobber) sendUploadRequest( } }() - if formData.FileBytesLen == 0 { - //fixed fileRef in last chunk on stream. io.EOF with nil bytes - if isFinal { - sb.fileRef.ChunkSize = su.chunkSize - sb.fileRef.Size = su.shardUploadedSize - sb.fileRef.Path = su.fileMeta.RemotePath - sb.fileRef.ActualFileHash = su.fileMeta.ActualHash - sb.fileRef.ActualFileSize = su.fileMeta.ActualSize - - sb.fileRef.EncryptedKey = encryptedKey - sb.fileRef.CalculateHash() - consensus.Done() - } - } - eg, _ := errgroup.WithContext(ctx) for dataInd := 0; dataInd < len(dataBuffers); dataInd++ { diff --git a/zboxcore/sdk/chunked_upload_form_builder.go b/zboxcore/sdk/chunked_upload_form_builder.go index 94cb956f5..e3c20a930 100644 --- a/zboxcore/sdk/chunked_upload_form_builder.go +++ b/zboxcore/sdk/chunked_upload_form_builder.go @@ -57,14 +57,13 @@ func (b *chunkedUploadFormBuilder) Build( var res blobberData - if len(fileChunksData) == 0 { - return res, nil - } - numBodies := len(fileChunksData) / MAX_BLOCKS if len(fileChunksData)%MAX_BLOCKS > 0 { numBodies++ } + if len(fileChunksData) == 0 { + numBodies = 1 + } dataBuffers := make([]*bytes.Buffer, 0, numBodies) contentSlice := make([]string, 0, numBodies) @@ -103,33 +102,34 @@ func (b *chunkedUploadFormBuilder) Build( body := bytes.NewBuffer(bodyBuf) formWriter := multipart.NewWriter(body) defer formWriter.Close() - - uploadFile, err := formWriter.CreateFormFile("uploadFile", formData.Filename) - if err != nil { - return res, err - } - - for _, chunkBytes := range fileChunksData[startRange:endRange] { - _, err = uploadFile.Write(chunkBytes) + if endRange > startRange { + uploadFile, err := formWriter.CreateFormFile("uploadFile", formData.Filename) if err != nil { return res, err } - err = hasher.WriteToFixedMT(chunkBytes) - if err != nil { - return res, err - } + for _, chunkBytes := range fileChunksData[startRange:endRange] { + _, err = uploadFile.Write(chunkBytes) + if err != nil { + return res, err + } - err = hasher.WriteToValidationMT(chunkBytes) - if err != nil { - return res, err - } + err = hasher.WriteToFixedMT(chunkBytes) + if err != nil { + return res, err + } + + err = hasher.WriteToValidationMT(chunkBytes) + if err != nil { + return res, err + } - metadata.FileBytesLen += len(chunkBytes) + metadata.FileBytesLen += len(chunkBytes) + } } if isFinal && i == numBodies-1 { - err = hasher.Finalize() + err := hasher.Finalize() if err != nil { return res, err } @@ -202,7 +202,7 @@ func (b *chunkedUploadFormBuilder) Build( formData.UploadOffset = formData.UploadOffset + chunkSize*int64(MAX_BLOCKS) } - err = formWriter.WriteField("connection_id", connectionID) + err := formWriter.WriteField("connection_id", connectionID) if err != nil { return res, err }