Skip to content

Commit

Permalink
Allow passing fileName in the StoreFileOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed May 30, 2023
1 parent ab0611e commit 10c29b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion IHP/FileStorage/ControllerFunctions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ storeFileWithOptions :: (?context :: context, ConfigProvider context) => Wai.Fil
storeFileWithOptions fileInfo options = do
objectId <- UUID.nextRandom

let fileName = options.fileName |> fromMaybe objectId

let directory = options.directory
let objectPath = directory <> "/" <> UUID.toText objectId
let objectPath = directory <> "/" <> UUID.toText fileName
let preprocess = options.preprocess

fileInfo <- preprocess fileInfo
Expand Down
2 changes: 2 additions & 0 deletions IHP/FileStorage/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ data StoreFileOptions = StoreFileOptions
{ directory :: Text -- ^ Directory on S3 or inside the @static@ where all files are placed
, contentDisposition :: Wai.FileInfo LByteString -> IO (Maybe Text) -- ^ The browser uses the content disposition header to detect if the file should be shown inside the browser or should be downloaded as a file attachment. You can provide a function here that returns a custom content-disposition header based on the uploaded file. This currently only works with the S3 storage. See 'contentDispositionAttachmentAndFileName' for standard configuration.
, preprocess :: Wai.FileInfo LByteString -> IO (Wai.FileInfo LByteString) -- ^ Can be used to preprocess the file before storing it inside the storage. See 'applyImageMagick' for preprocessing images.
, fileName :: Maybe UUID -- ^ Optional filename. We use UUID for security measures.
}

instance Default StoreFileOptions where
def = StoreFileOptions
{ directory = ""
, contentDisposition = const (pure Nothing)
, preprocess = pure
, fileName = Nothing
}

-- | A signed url to a file. See 'createTemporaryDownloadUrl'
Expand Down

0 comments on commit 10c29b7

Please sign in to comment.