-
Notifications
You must be signed in to change notification settings - Fork 93
fix: Set content type when uploading dispute evidence #4959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,27 @@ let getFileTypeFromFileName = fileName => { | |
| afterDotFileType | ||
| } | ||
|
|
||
| @get external getFileMimeType: 'a => string = "type" | ||
|
|
||
| let getMimeTypeFromFileName = fileName => { | ||
| switch fileName->getFileTypeFromFileName->String.toLowerCase { | ||
| | "pdf" => "application/pdf" | ||
| | "csv" => "text/csv" | ||
| | "jpeg" | "jpg" => "image/jpeg" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good defensive coding with the |
||
| | "png" => "image/png" | ||
| | _ => "application/octet-stream" | ||
| } | ||
| } | ||
|
|
||
| // Some browsers report an empty `File.type` (e.g. for csv or unrecognised files). | ||
| // Uploading such a file leaves the multipart part without a Content-Type, which the | ||
| // backend rejects with IR_36 ("File content type not found"). Fall back to a MIME | ||
| // type derived from the file extension so a Content-Type is always present. | ||
| let getEvidenceFileContentType = (fileValue, fileName) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this too can be dropped. |
||
| let fileMimeType = fileValue->getFileMimeType | ||
| fileMimeType->isNonEmptyString ? fileMimeType : fileName->getMimeTypeFromFileName | ||
| } | ||
|
|
||
| let (startTimeFilterKey, endTimeFilterKey) = ("start_time", "end_time") | ||
|
|
||
| let getFilterTypeFromString = filterType => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ module EvidenceUploadForm = { | |
| <input | ||
| key={Int.toString(index)} | ||
| type_="file" | ||
| accept=".pdf,.csv,.img,.jpeg" | ||
| accept=".pdf,.csv,.jpeg,.jpg,.png" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good fix removing |
||
| onChange={ev => ev->handleBrowseChange(uploadEvidenceType)} | ||
| hidden=true | ||
| /> | ||
|
|
@@ -83,12 +83,14 @@ module UploadDisputeEvidenceModal = { | |
| open LogicUtils | ||
| let getURL = useGetURL() | ||
| let updateDetails = useUpdateMethod() | ||
| let acceptFile = (keyValue, fileValue) => { | ||
| let acceptFile = (keyValue, fileValue, fileName) => { | ||
| let url = getURL(~entityName=V1(DISPUTES_ATTACH_EVIDENCE), ~methodType=Put) | ||
| let formData = formData() | ||
| append(formData, "dispute_id", disputeId) | ||
| append(formData, "evidence_type", keyValue) | ||
| append(formData, "file", fileValue) | ||
| let contentType = DisputesUtils.getEvidenceFileContentType(fileValue, fileName) | ||
| let fileBlob = blob([fileValue], {"type": contentType}) | ||
| appendBlob(formData, "file", fileBlob, fileName) | ||
|
|
||
| updateDetails( | ||
| ~bodyFormData=formData, | ||
|
|
@@ -111,7 +113,8 @@ module UploadDisputeEvidenceModal = { | |
| let promisesOfAttachEvidence = dictToIterate->Array.map(ele => { | ||
| let jsonObject = fileUploadedDict->Dict.get(ele)->Option.getOr(JSON.Encode.null) | ||
| let fileValue = jsonObject->getDictFromJsonObject->getJsonObjectFromDict("uploadedFile") | ||
| let res = acceptFile(ele, fileValue) | ||
| let fileName = jsonObject->getDictFromJsonObject->getString("fileName", "") | ||
| let res = acceptFile(ele, fileValue, fileName) | ||
| res | ||
| }) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the accept filter constrains uploads to known extensions, deriving the MIME from the filename is always sufficient.
we can drop this
@get external getFileMimeType