Skip to content

Commit

Permalink
Merge pull request #955 from nextcloud-libraries/bugfix/926
Browse files Browse the repository at this point in the history
fix: Do not block if the filetype is unknown to the browser
  • Loading branch information
juliusknorr authored Nov 15, 2023
2 parents 4188caf + e78aae3 commit 24a1850
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 5 additions & 2 deletions __tests__/utils/upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ describe('Get chunk from file', () => {
expect(chunk.size).toBe(10 * 1024 * 1024)
})

test('Chunking an invalid file', () => {
test('Chunking an invalid file', async () => {
const blob = new Blob([new ArrayBuffer(5 * 1024 * 1024)])
const file = new File([blob as BlobPart], 'image.jpg')

expect(getChunk(file, 0, 10 * 1024 * 1024)).rejects.toEqual(new Error('Unknown file type'))
const chunk = await getChunk(file, 0, 10 * 1024 * 1024)
expect(chunk.size).toBe(5 * 1024 * 1024)
expect(chunk.type).toBe('application/octet-stream')

})
})

Expand Down
4 changes: 0 additions & 4 deletions lib/utils/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ export const uploadData = async function(url: string, uploadData: UploadData, si
* garbage collection
*/
export const getChunk = function(file: File, start: number, length: number): Promise<Blob> {
if (!file.type) {
return Promise.reject(new Error('Unknown file type'))
}

// Since we use a global FileReader, we need to only read one chunk at a time
return readerLimit(() => new Promise((resolve, reject) => {
reader.onload = () => {
Expand Down

0 comments on commit 24a1850

Please sign in to comment.