(files: File[])
| 80 | } |
| 81 | |
| 82 | export async function getFormData(files: File[]) { |
| 83 | const data = new FormData(); |
| 84 | for (let index = 0, length = files.length; index < length; index++) { |
| 85 | const file = files[index]; |
| 86 | if (isImage(file.name)) { |
| 87 | try { |
| 88 | const { width, height } = await fetchImageDimensions(file); |
| 89 | const extension = getExtension(file.name) as string; |
| 90 | const name = |
| 91 | file.name.substring(0, file.name.length - extension.length - 1) + |
| 92 | `_${width}x${height}.${extension}`; |
| 93 | data.append(`file-${index}`, file, name); |
| 94 | } catch (exception) { |
| 95 | data.append(`file-${index}`, file, file.name); |
| 96 | } |
| 97 | } else { |
| 98 | data.append(`file-${index}`, file, file.name); |
| 99 | } |
| 100 | } |
| 101 | return data; |
| 102 | } |
no test coverage detected