Skip to content

Commit

Permalink
Merge pull request #436 from oneblink/ON-43615
Browse files Browse the repository at this point in the history
ON-43615 # Setting of `contentType` to use detection when content typ…
  • Loading branch information
RyanButton authored Sep 25, 2024
2 parents 1d38181 + ce87385 commit 19e5283
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Setting of `contentType` to use detection when content type is not provided

## [16.0.0] - 2024-09-25

### Added
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@sentry/tracing": "^7.77.0",
"date-fns": "^2.30.0",
"file-saver": "^2.0.5",
"file-type-checker": "^1.1.2",
"jwt-decode": "^4.0.0",
"localforage": "^1.10.0",
"lodash.clonedeep": "^4.5.0",
Expand Down
4 changes: 3 additions & 1 deletion src/approvals-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export type FormSubmissionApprovalsResponse = {
formSubmissionApproval: ApprovalTypes.FormSubmissionApproval
formApprovalFlowInstance: ApprovalTypes.FormApprovalFlowInstance
formSubmissionMeta: SubmissionTypes.FormSubmissionMeta
latestSuccessfulFormSubmissionPayment: SubmissionTypes.FormSubmissionPayment | undefined
latestSuccessfulFormSubmissionPayment:
| SubmissionTypes.FormSubmissionPayment
| undefined
}>
}

Expand Down
12 changes: 10 additions & 2 deletions src/services/uploadAttachment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SubmissionTypes } from '@oneblink/types'
import { ProgressListener } from '../types/submissions'
import generateOneBlinkUploader from './generateOneBlinkUploader'
import fileTypeChecker from 'file-type-checker'

export type UploadAttachmentConfiguration = {
fileName: string
Expand Down Expand Up @@ -64,8 +65,15 @@ export default async function uploadAttachment(
abortSignal?: AbortSignal,
): Promise<SubmissionTypes.FormSubmissionAttachment> {
const oneblinkUploader = generateOneBlinkUploader()
// S3 defaults unknown file types to the following, do the same here for our submission model
const _contentType = contentType || 'application/octet-stream'

let _contentType = contentType || 'application/octet-stream' // S3 default for unknown content type
if (!contentType) {
const buffer = await data.arrayBuffer()
const detectedType = fileTypeChecker.detectFile(buffer)
if (detectedType) {
_contentType = detectedType.mimeType
}
}
const result = await oneblinkUploader.uploadAttachment({
formId,
fileName,
Expand Down

0 comments on commit 19e5283

Please sign in to comment.