From f7d11f87c1d53bfbeb0f762bc7816c408c7be2a4 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Fri, 19 May 2017 10:59:12 +0200 Subject: [PATCH] mediaapi/writers/upload: Add comment about why we hash the file data --- .../matrix-org/dendrite/mediaapi/writers/upload.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go b/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go index 943fbb659..05db45630 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go @@ -157,6 +157,10 @@ func writeFileWithLimitAndHash(r io.Reader, cfg *config.MediaAPI, logger *log.En // The limited reader restricts how many bytes are read from the body to the specified maximum bytes // Note: the golang HTTP server closes the request body limitedBody := io.LimitReader(r, int64(cfg.MaxFileSizeBytes)) + // The file data is hashed and the hash is returned. The hash is useful as a + // method of deduplicating files to save storage, as well as a way to conduct + // integrity checks on the file data in the repository. The hash gets used as + // the MediaID. hasher := sha256.New() reader := io.TeeReader(limitedBody, hasher) @@ -243,6 +247,9 @@ func Upload(req *http.Request, cfg *config.MediaAPI, db *storage.Database) util. "Content-Disposition": r.MediaMetadata.ContentDisposition, }).Info("Uploading file") + // The file data is hashed and the hash is used as the MediaID. The hash is useful as a + // method of deduplicating files to save storage, as well as a way to conduct + // integrity checks on the file data in the repository. hash, tmpDir, resErr := writeFileWithLimitAndHash(req.Body, cfg, logger, r.MediaMetadata.ContentLength) if resErr != nil { return *resErr