Fix file replacing not working

This commit is contained in:
rijkvanzanten
2020-08-13 11:11:31 -04:00
parent 2c10fd582e
commit 2d59995468

View File

@@ -21,6 +21,8 @@ const multipartHandler = asyncHandler(async (req, res, next) => {
const savedFiles: PrimaryKey[] = [];
const service = new FilesService({ accountability: req.accountability });
const existingPrimaryKey = req.params.pk || undefined;
/**
* The order of the fields in multipart/form-data is important. We require that all fields
* are provided _before_ the files. This allows us to set the storage location, and create
@@ -61,7 +63,7 @@ const multipartHandler = asyncHandler(async (req, res, next) => {
storage: payload.storage || disk,
};
const primaryKey = await service.upload(fileStream, payloadWithRequiredFields);
const primaryKey = await service.upload(fileStream, payloadWithRequiredFields, existingPrimaryKey);
savedFiles.push(primaryKey);
tryDone();
});