diff --git a/code/go/0chain.net/blobbercore/filestore/storage.go b/code/go/0chain.net/blobbercore/filestore/storage.go index 9109b2a5f..c39e10397 100644 --- a/code/go/0chain.net/blobbercore/filestore/storage.go +++ b/code/go/0chain.net/blobbercore/filestore/storage.go @@ -72,6 +72,17 @@ func (fs *FileStore) WriteFile(allocID, conID string, fileData *FileInputData, i initialSize = finfo.Size() } + if infile == nil { + if finfo == nil { + return nil, common.NewError("file_not_found", "Temp File not found") + } + return &FileOutputData{ + Name: fileData.Name, + Path: fileData.Path, + ContentSize: initialSize, + }, nil + } + if err = createDirs(filepath.Dir(tempFilePath)); err != nil { return nil, common.NewError("dir_creation_error", err.Error()) } @@ -106,7 +117,7 @@ func (fs *FileStore) WriteFile(allocID, conID string, fileData *FileInputData, i _ = os.Remove(tempFilePath) return nil, common.NewError("file_size_mismatch", "File size is greater than expected") } - logging.Logger.Info("temp_file_write: ", zap.String("filePath", fileData.Path), zap.Int64("currentSize", currentSize), zap.Int64("initialSize", initialSize), zap.Int64("writtenSize", writtenSize), zap.Int64("offset", fileData.UploadOffset), zap.Bool("ChunkUploaded", fileRef.ChunkUploaded)) + logging.Logger.Info("temp_file_write: ", zap.String("filePath", fileData.Path), zap.Int64("currentSize", currentSize), zap.Int64("initialSize", initialSize), zap.Int64("writtenSize", writtenSize), zap.Int64("offset", fileData.UploadOffset)) fileRef.Size = writtenSize fileRef.Name = fileData.Name fileRef.Path = fileData.Path diff --git a/code/go/0chain.net/blobbercore/handler/file_command_update.go b/code/go/0chain.net/blobbercore/handler/file_command_update.go index 20f931744..eab4dc6f5 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_update.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_update.go @@ -98,7 +98,9 @@ func (cmd *UpdateFileCommand) IsValidated(ctx context.Context, req *http.Request } origfile, _, err := req.FormFile(UploadFile) - if err != nil { + if err == http.ErrMissingFile && !cmd.fileChanger.IsFinal { + return common.NewError("invalid_parameters", "File is missing") + } else if err != nil && err != http.ErrMissingFile { return common.NewError("invalid_parameters", "Error Reading multi parts for file."+err.Error()) } cmd.contentFile = origfile @@ -110,7 +112,9 @@ func (cmd *UpdateFileCommand) ProcessContent(allocationObj *allocation.Allocatio result := allocation.UploadResult{} result.Filename = cmd.fileChanger.Filename - defer cmd.contentFile.Close() + if cmd.contentFile != nil { + defer cmd.contentFile.Close() + } filePathHash := cmd.fileChanger.PathHash connID := cmd.fileChanger.ConnectionID diff --git a/code/go/0chain.net/blobbercore/handler/file_command_upload.go b/code/go/0chain.net/blobbercore/handler/file_command_upload.go index a28fa3163..18ec95a2d 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_upload.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_upload.go @@ -113,7 +113,9 @@ func (cmd *UploadFileCommand) IsValidated(ctx context.Context, req *http.Request } origfile, _, err := req.FormFile(UploadFile) - if err != nil { + if err == http.ErrMissingFile && !fileChanger.IsFinal { + return common.NewError("invalid_parameters", "Missing file") + } else if err != nil && err != http.ErrMissingFile { return common.NewError("invalid_parameters", "Error Reading multi parts for file."+err.Error()) } cmd.contentFile = origfile @@ -125,7 +127,9 @@ func (cmd *UploadFileCommand) IsValidated(ctx context.Context, req *http.Request func (cmd *UploadFileCommand) ProcessContent(allocationObj *allocation.Allocation) (allocation.UploadResult, error) { logging.Logger.Info("UploadFileCommand.ProcessContent", zap.Any("fileChanger", cmd.fileChanger.Path), zap.Any("uploadOffset", cmd.fileChanger.UploadOffset), zap.Any("isFinal", cmd.fileChanger.IsFinal)) result := allocation.UploadResult{} - defer cmd.contentFile.Close() + if cmd.contentFile != nil { + defer cmd.contentFile.Close() + } connectionID := cmd.fileChanger.ConnectionID