mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 21:24:33 +03:00
Merge pull request #5176 from levic/browsable-api-multipart-form-data
Fix browsable API not supporting multipart/form-data correctly
This commit is contained in:
commit
b069b0d33a
|
@ -37,6 +37,21 @@ function doAjaxSubmit(e) {
|
||||||
|
|
||||||
if (contentType) {
|
if (contentType) {
|
||||||
data = form.find('[data-override="content"]').val() || ''
|
data = form.find('[data-override="content"]').val() || ''
|
||||||
|
|
||||||
|
if (contentType === 'multipart/form-data') {
|
||||||
|
// We need to add a boundary parameter to the header
|
||||||
|
// We assume the first valid-looking boundary line in the body is correct
|
||||||
|
// regex is from RFC 2046 appendix A
|
||||||
|
var boundaryCharNoSpace = "0-9A-Z'()+_,-./:=?";
|
||||||
|
var boundaryChar = boundaryCharNoSpace + ' ';
|
||||||
|
var re = new RegExp('^--([' + boundaryChar + ']{0,69}[' + boundaryCharNoSpace + '])[\\s]*?$', 'im');
|
||||||
|
var boundary = data.match(re);
|
||||||
|
if (boundary !== null) {
|
||||||
|
contentType += '; boundary="' + boundary[1] + '"';
|
||||||
|
}
|
||||||
|
// Fix textarea.value EOL normalisation (multipart/form-data should use CR+NL, not NL)
|
||||||
|
data = data.replace(/\n/g, '\r\n');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
contentType = form.attr('enctype') || form.attr('encoding')
|
contentType = form.attr('enctype') || form.attr('encoding')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user