Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion code/go/0chain.net/blobbercore/filestore/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down