diff --git a/lib/adapters/fetch.js b/lib/adapters/fetch.js index 0ac9650..d053e57 100644 --- a/lib/adapters/fetch.js +++ b/lib/adapters/fetch.js @@ -59,6 +59,10 @@ isFetchSupported && (((res) => { })(new Response)); const getBodyLength = async (body) => { + if (body == null) { + return 0; + } + if(utils.isBlob(body)) { return body.size; } @@ -117,10 +121,13 @@ export default isFetchSupported && (async (config) => { finished = true; } - try { - if (onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head') { - let requestContentLength = await resolveBodyLength(headers, data); + let requestContentLength; + try { + if ( + onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' && + (requestContentLength = await resolveBodyLength(headers, data)) !== 0 + ) { let _request = new Request(url, { method: 'POST', body: data, @@ -133,10 +140,12 @@ export default isFetchSupported && (async (config) => { headers.setContentType(contentTypeHeader) } - data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator( - requestContentLength, - progressEventReducer(onUploadProgress) - )); + if (_request.body) { + data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator( + requestContentLength, + progressEventReducer(onUploadProgress) + )); + } } if (!utils.isString(withCredentials)) {