Created
May 25, 2020 13:12
-
-
Save threeaccents/8690a5c0d2b900b73ca5a2180f578df4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (s *Service) ChunkUpload(ctx context.Context, r *multipart.Reader) error { | |
chunk, err := s.parseChunk(r) | |
if err != nil { | |
return fmt.Errorf("failed parsing chunk %w", err) | |
} | |
// checkpoint | |
select { | |
case <-ctx.Done(): | |
// Abort / return early | |
return ctx.Err() | |
default: | |
} | |
if err := os.MkdirAll(chunk.UploadDir, 02750); err != nil { | |
return err | |
} | |
// checkpoint | |
select { | |
case <-ctx.Done(): | |
// Abort / return early | |
return ctx.Err() | |
default: | |
} | |
if err := s.saveChunk(chunk); err != nil { | |
return fmt.Errorf("failed saving chunk %w", err) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment