Skip to content

Commit

Permalink
fix to use proper field addressing when upload (#1396)
Browse files Browse the repository at this point in the history
* fix to use proper field addressing when upload

* be consistent w chunkFormData value

* remove new value set from upload control

* mod file upload test not to expect fieldonchange
  • Loading branch information
VargaJoe authored Jun 10, 2022
1 parent 4bc6860 commit 2332398
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/sn-client-core/src/Repository/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export class Upload {

const chunkToken = await initRequest.text()
let lastResponseContent: UploadResponse = {} as any

for (let i = 0; i <= chunkCount; i++) {
const start = i * this.repository.configuration.chunkSize
let end = start + this.repository.configuration.chunkSize
Expand All @@ -191,6 +190,7 @@ export class Upload {

chunkFormData.append('FileLength', options.file.size.toString())
chunkFormData.append('ChunkToken', chunkToken)
chunkFormData.append('PropertyName', options.binaryPropertyName.toString())
chunkFormData.append(options.file.name, chunkData)

const lastResponse = await this.repository.fetch(uploadPath, {
Expand Down
3 changes: 1 addition & 2 deletions packages/sn-controls-react/src/fieldcontrols/file-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ export const FileUpload: React.FC<ReactClientFieldSetting<BinaryFieldSetting>> =
fileName: props.content.Name,
overwrite: true,
contentTypeName: props.content.Type,
binaryPropertyName: 'Binary',
binaryPropertyName: props.settings.Name,
})

const newValue = `${getNameFromPath(e.target.value)}`
setFileName(newValue)
props.fieldOnChange?.(props.settings.Name, newValue)
} catch (error) {
console.error(error.message)
}
Expand Down
1 change: 0 additions & 1 deletion packages/sn-controls-react/test/file-upload.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ describe('File upload field control', () => {

wrapper.find(Input).simulate('change', { target: { files: [], value: 'somePath' }, persist: jest.fn() })
await sleepAsync(0)
expect(fieldOnChange).toBeCalled()
expect(repository.upload.file).toBeCalled()
})

Expand Down

0 comments on commit 2332398

Please sign in to comment.