-
Notifications
You must be signed in to change notification settings - Fork 1
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
[MPDX-8440] Remove TNT import file upload restriction #1180
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,26 +13,19 @@ export const validateTnt = ({ | |
message: t('Cannot upload file: file must be a xml file'), | ||
}; | ||
} | ||
// The /api lambda appears to truncate the source body at 2^20 bytes | ||
// Conservatively set the limit at 1MB, which is a little lower than 1MiB because of the | ||
// overhead of encoding multipart/form-data and the other fields in the POST body | ||
if (file.size > 1_000_000) { | ||
return { | ||
success: false, | ||
message: t('Cannot upload file: file size cannot exceed 1MB'), | ||
}; | ||
} | ||
|
||
return { success: true }; | ||
}; | ||
|
||
export const uploadTnt = async ({ | ||
apiToken, | ||
selectedTags, | ||
override, | ||
file, | ||
t, | ||
accountListId, | ||
}: { | ||
apiToken: string; | ||
selectedTags: string[]; | ||
override: string; | ||
file: File; | ||
|
@@ -45,19 +38,24 @@ export const uploadTnt = async ({ | |
} | ||
|
||
const form = new FormData(); | ||
form.append('override', override); | ||
form.append('tag_list', selectedTags.join(',')); | ||
form.append('file', file); | ||
form.append('accountListId', accountListId); | ||
form.append('data[type]', 'imports'); | ||
form.append('data[attributes][override]', override); | ||
form.append('data[attributes][tag_list]', selectedTags.join(',')); | ||
form.append('data[attributes][file]', file); | ||
|
||
const res = await fetch(`/api/uploads/upload-tnt-connect-import`, { | ||
method: 'POST', | ||
body: form, | ||
}).catch((err) => { | ||
throw new Error(t('Cannot upload file: server error') + err); | ||
const res = await fetch( | ||
`${process.env.REST_API_URL}account_lists/${accountListId}/imports/tnt`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
authorization: `Bearer ${apiToken}`, | ||
}, | ||
body: form, | ||
}, | ||
).catch(() => { | ||
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.
|
||
throw new Error(t('Cannot upload file: network error')); | ||
}); | ||
const data: { success: boolean } = await res.json(); | ||
if (!data.success) { | ||
throw new Error(t('Cannot upload file: server not successful') + data); | ||
if (!res.ok) { | ||
throw new Error(t('Cannot upload file: server not successful')); | ||
} | ||
}; |
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.
The old blob will already be released by the
useEffect
cleanup function on line 164.