Occasional 400 errors when uploading images using /images/v2/direct_upload

Hello, I get 400 when uploading images quite often (sometimes it can be like 10% of requests) which is frustrating. Is there a way to make the upload more stable?

Here’s what I receive in such cases:

2023-03-28 11:14:26 {
2023-03-28 11:14:26   status: 400,
2023-03-28 11:14:26   statusText: 'Bad Request',
2023-03-28 11:14:26   headers: AxiosHeaders {
2023-03-28 11:14:26     date: 'Tue, 28 Mar 2023 09:14:24 GMT',
2023-03-28 11:14:26     'content-type': 'text/plain;charset=utf-8',
2023-03-28 11:14:26     'content-length': '53',
2023-03-28 11:14:26     connection: 'close',
2023-03-28 11:14:26     'cf-ray': '7aeec3382bbc34f7-WAW',
2023-03-28 11:14:26     'access-control-allow-origin': '*',
2023-03-28 11:14:26     'cache-control': 'no-cache',
2023-03-28 11:14:26     'set-cookie': [
2023-03-28 11:14:26       'CF_Authorization=eyJraWQiOiIxY2MwYzVmNDJiNmE1NjkxY2MzZDVjOWQ0NDhjZWJhMTk1ZjJlOWQ5MjVkNDEyOWYzZGNlNjE5MDY2YTQ2ZDQ5IiwiYWxnIjoiUlMyNTYiLCJ0eXAiOiJKV1QifQ.eyJ0eXBlIjoiYXBwIiwiYXVkIjoiNjljZTkxNThjM2JiZDFlZGI0NTk5ZWFhZGE5Yjg5MmVjZmExMjUzOTNlMjJjZTEzODBlNDliYWQxMDMxNTIwOCIsImV4cCI6MTY4MDA4MTI2MywiaXNzIjoiaHR0cHM6XC9cL3NwZWVkY2YuY2xvdWRmbGFyZWFjY2Vzcy5jb20iLCJjb21tb25fbmFtZSI6IjFmNWNjNGZjMGI3ZTU4Mjk0ZDMxMDJhNTEyMzVkMzM3LmFjY2VzcyIsImlhdCI6MTY3OTk5NDg2Mywic3ViIjoiIn0.FrFu0-WkXKxIOrmYErkKa2GsyINWkIR5MB4n4HKV_A8CHuGUn4E4e8rjOFW0og74K8MeipDhwh4h3hm067XunRkAOLRMfeKTP4TUuqsO2PQTsx1nCcxZG42c66fsrUw_NS2-EoxJEagcfKWD8bINOBXOhXi_looVGxPmmTdmCAHmRY6PALu8pT7WZcx81rVulr9MJy3v5aslVV-MkAipGccmH9Q5XNbgOUqqCjZ7_iFu9mPk3Vt1l5XcdFeDvfWzrGxZrK5PZobJH6Ycpi6gedXHlPiW1_a9HI4tBesITWMgvkYypCY4EvGdnGujRNeSt8sBTezraxRoCAasFJ6NEQ; Expires=Wed, 29 Mar 2023 09:14:23 GMT; Path=/; Secure; SameSite=none',
2023-03-28 11:14:26       '__cf_bm=Sd_Jh1RZZUhogWaQEiZrBtA5DtYPWy8FTdXVWFL7Hgg-1679994864-0-ASp7gDulAzJRL/gMVn7jatGUqZAk8tyoyzCdrwBjV+LvcPORukwnU8iN/KyGPS0EN88Trf6kjPkzy1eE4xY8ceE=; path=/; expires=Tue, 28-Mar-23 09:44:24 GMT; domain=.speedcf.com; HttpOnly; Secure'
2023-03-28 11:14:26     ],
2023-03-28 11:14:26     'cf-cache-status': 'DYNAMIC',
2023-03-28 11:14:26     'cf-images': 'err=5400',
2023-03-28 11:14:26     'x-content-type-options': 'nosniff',
2023-03-28 11:14:26     vary: 'Accept-Encoding',
2023-03-28 11:14:26     server: 'cloudflare',
2023-03-28 11:14:26     'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400'
2023-03-28 11:14:26   },
2023-03-28 11:14:26   config: {
2023-03-28 11:14:26     transitional: {
2023-03-28 11:14:26       silentJSONParsing: true,
2023-03-28 11:14:26       forcedJSONParsing: true,
2023-03-28 11:14:26       clarifyTimeoutError: false
2023-03-28 11:14:26     },
2023-03-28 11:14:26     adapter: [ 'xhr', 'http' ],
2023-03-28 11:14:26     transformRequest: [ [Function: transformRequest] ],
2023-03-28 11:14:26     transformResponse: [ [Function: transformResponse] ],
2023-03-28 11:14:26     timeout: 0,
2023-03-28 11:14:26     xsrfCookieName: 'XSRF-TOKEN',
2023-03-28 11:14:26     xsrfHeaderName: 'X-XSRF-TOKEN',
2023-03-28 11:14:26     maxContentLength: -1,
2023-03-28 11:14:26     maxBodyLength: -1,
2023-03-28 11:14:26     env: { FormData: [Function], Blob: [class Blob] },
2023-03-28 11:14:26     validateStatus: [Function: validateStatus],
2023-03-28 11:14:26     headers: AxiosHeaders {
2023-03-28 11:14:26       Accept: 'application/json, text/plain, */*',
2023-03-28 11:14:26       'Content-Type': 'multipart/form-data; boundary=--------------------------635703211465585932851466',
2023-03-28 11:14:26       'User-Agent': 'axios/1.2.1',
2023-03-28 11:14:26       'Accept-Encoding': 'gzip, compress, deflate, br'
2023-03-28 11:14:26     },
2023-03-28 11:14:26     method: 'post',
2023-03-28 11:14:26     url: 'https://upload.imagedelivery.net/ZBEqKIKgZgKrPlD3ay4FLg/432f6ebf-dd9f-4e1c-9d0a-28f42c0c6800',
2023-03-28 11:14:26     data: FormData {
2023-03-28 11:14:26       _overheadLength: 176,
2023-03-28 11:14:26       _valueLength: 437267,
2023-03-28 11:14:26       _valuesToMeasure: [],
2023-03-28 11:14:26       writable: false,
2023-03-28 11:14:26       readable: true,
2023-03-28 11:14:26       dataSize: 0,
2023-03-28 11:14:26       maxDataSize: 2097152,
2023-03-28 11:14:26       pauseStreams: true,
2023-03-28 11:14:26       _released: true,
2023-03-28 11:14:26       _streams: [],
2023-03-28 11:14:26       _currentStream: null,
2023-03-28 11:14:26       _insideLoop: false,
2023-03-28 11:14:26       _pendingNext: false,
2023-03-28 11:14:26       _boundary: '--------------------------635703211465585932851466',
2023-03-28 11:14:26       _events: [Object: null prototype],
2023-03-28 11:14:26       _eventsCount: 3
2023-03-28 11:14:26     }
2023-03-28 11:14:26   },
2023-03-28 11:14:26   request: <ref *1> ClientRequest {
2023-03-28 11:14:26     _events: [Object: null prototype] {
2023-03-28 11:14:26       abort: [Function (anonymous)],
2023-03-28 11:14:26       aborted: [Function (anonymous)],
2023-03-28 11:14:26       connect: [Function (anonymous)],
2023-03-28 11:14:26       error: [Function (anonymous)],
2023-03-28 11:14:26       socket: [Function (anonymous)],
2023-03-28 11:14:26       timeout: [Function (anonymous)],
2023-03-28 11:14:26       finish: [Function: requestOnFinish]
2023-03-28 11:14:26     },
2023-03-28 11:14:26     _eventsCount: 7,
2023-03-28 11:14:26     _maxListeners: undefined,
2023-03-28 11:14:26     outputData: [],
2023-03-28 11:14:26     outputSize: 0,
2023-03-28 11:14:26     writable: true,
2023-03-28 11:14:26     destroyed: false,
2023-03-28 11:14:26     _last: true,
2023-03-28 11:14:26     chunkedEncoding: true,
2023-03-28 11:14:26     shouldKeepAlive: false,
2023-03-28 11:14:26     maxRequestsOnConnectionReached: false,
2023-03-28 11:14:26     _defaultKeepAlive: true,
2023-03-28 11:14:26     useChunkedEncodingByDefault: true,
2023-03-28 11:14:26     sendDate: false,
2023-03-28 11:14:26     _removedConnection: false,
2023-03-28 11:14:26     _removedContLen: false,
2023-03-28 11:14:26     _removedTE: false,
2023-03-28 11:14:26     strictContentLength: false,
2023-03-28 11:14:26     _contentLength: null,
2023-03-28 11:14:26     _hasBody: true,
2023-03-28 11:14:26     _trailer: '',
2023-03-28 11:14:26     finished: true,
2023-03-28 11:14:26     _headerSent: true,
2023-03-28 11:14:26     _closed: false,
2023-03-28 11:14:26     socket: TLSSocket {
2023-03-28 11:14:26       _tlsOptions: [Object],
2023-03-28 11:14:26       _secureEstablished: true,
2023-03-28 11:14:26       _securePending: false,
2023-03-28 11:14:26       _newSessionPending: false,
2023-03-28 11:14:26       _controlReleased: true,
2023-03-28 11:14:26       secureConnecting: false,
2023-03-28 11:14:26       _SNICallback: null,
2023-03-28 11:14:26       servername: 'upload.imagedelivery.net',
2023-03-28 11:14:26       alpnProtocol: false,
2023-03-28 11:14:26       authorized: true,
2023-03-28 11:14:26       authorizationError: null,
2023-03-28 11:14:26       encrypted: true,
2023-03-28 11:14:26       _events: [Object: null prototype],
2023-03-28 11:14:26       _eventsCount: 10,
2023-03-28 11:14:26       connecting: false,
2023-03-28 11:14:26       _hadError: false,
2023-03-28 11:14:26       _parent: null,
2023-03-28 11:14:26       _host: 'upload.imagedelivery.net',
2023-03-28 11:14:26       _closeAfterHandlingError: false,
2023-03-28 11:14:26       _readableState: [ReadableState],
2023-03-28 11:14:26       _maxListeners: undefined,
2023-03-28 11:14:26       _writableState: [WritableState],
2023-03-28 11:14:26       allowHalfOpen: false,
2023-03-28 11:14:26       _sockname: null,
2023-03-28 11:14:26       _pendingData: null,
2023-03-28 11:14:26       _pendingEncoding: '',
2023-03-28 11:14:26       server: undefined,
2023-03-28 11:14:26       _server: null,
2023-03-28 11:14:26       ssl: [TLSWrap],
2023-03-28 11:14:26       _requestCert: true,
2023-03-28 11:14:26       _rejectUnauthorized: true,
2023-03-28 11:14:26       parser: null,
2023-03-28 11:14:26       _httpMessage: [Circular *1],
2023-03-28 11:14:26       [Symbol(res)]: [TLSWrap],
2023-03-28 11:14:26       [Symbol(verified)]: true,
2023-03-28 11:14:26       [Symbol(pendingSession)]: null,
2023-03-28 11:14:26       [Symbol(async_id_symbol)]: 6083,
2023-03-28 11:14:26       [Symbol(kHandle)]: [TLSWrap],
2023-03-28 11:14:26       [Symbol(lastWriteQueueSize)]: 0,
2023-03-28 11:14:26       [Symbol(timeout)]: null,
2023-03-28 11:14:26       [Symbol(kBuffer)]: null,
2023-03-28 11:14:26       [Symbol(kBufferCb)]: null,
2023-03-28 11:14:26       [Symbol(kBufferGen)]: null,
2023-03-28 11:14:26       [Symbol(kCapture)]: false,
2023-03-28 11:14:26       [Symbol(kSetNoDelay)]: false,
2023-03-28 11:14:26       [Symbol(kSetKeepAlive)]: true,
2023-03-28 11:14:26       [Symbol(kSetKeepAliveInitialDelay)]: 60,
2023-03-28 11:14:26       [Symbol(kBytesRead)]: 0,
2023-03-28 11:14:26       [Symbol(kBytesWritten)]: 0,
2023-03-28 11:14:26       [Symbol(connect-options)]: [Object]
2023-03-28 11:14:26     },
2023-03-28 11:14:26     _header: 'POST /ZBEqKIKgZgKrPlD3ay4FLg/432f6ebf-dd9f-4e1c-9d0a-28f42c0c6800 HTTP/1.1\r\n' +
2023-03-28 11:14:26       'Accept: application/json, text/plain, */*\r\n' +
2023-03-28 11:14:26       'Content-Type: multipart/form-data; boundary=--------------------------635703211465585932851466\r\n' +
2023-03-28 11:14:26       'User-Agent: axios/1.2.1\r\n' +
2023-03-28 11:14:26       'Accept-Encoding: gzip, compress, deflate, br\r\n' +
2023-03-28 11:14:26       'Host: upload.imagedelivery.net\r\n' +
2023-03-28 11:14:26       'Connection: close\r\n' +
2023-03-28 11:14:26       'Transfer-Encoding: chunked\r\n' +
2023-03-28 11:14:26       '\r\n',
2023-03-28 11:14:26     _keepAliveTimeout: 0,
2023-03-28 11:14:26     _onPendingData: [Function: nop],
2023-03-28 11:14:26     agent: Agent {
2023-03-28 11:14:26       _events: [Object: null prototype],
2023-03-28 11:14:26       _eventsCount: 2,
2023-03-28 11:14:26       _maxListeners: undefined,
2023-03-28 11:14:26       defaultPort: 443,
2023-03-28 11:14:26       protocol: 'https:',
2023-03-28 11:14:26       options: [Object: null prototype],
2023-03-28 11:14:26       requests: [Object: null prototype] {},
2023-03-28 11:14:26       sockets: [Object: null prototype],
2023-03-28 11:14:26       freeSockets: [Object: null prototype] {},
2023-03-28 11:14:26       keepAliveMsecs: 1000,
2023-03-28 11:14:26       keepAlive: false,
2023-03-28 11:14:26       maxSockets: Infinity,
2023-03-28 11:14:26       maxFreeSockets: 256,
2023-03-28 11:14:26       scheduling: 'lifo',
2023-03-28 11:14:26       maxTotalSockets: Infinity,
2023-03-28 11:14:26       totalSocketCount: 1,
2023-03-28 11:14:26       maxCachedSessions: 100,
2023-03-28 11:14:26       _sessionCache: [Object],
2023-03-28 11:14:26       [Symbol(kCapture)]: false
2023-03-28 11:14:26     },
2023-03-28 11:14:26     socketPath: undefined,
2023-03-28 11:14:26     method: 'POST',
2023-03-28 11:14:26     maxHeaderSize: undefined,
2023-03-28 11:14:26     insecureHTTPParser: undefined,
2023-03-28 11:14:26     path: '/ZBEqKIKgZgKrPlD3ay4FLg/432f6ebf-dd9f-4e1c-9d0a-28f42c0c6800',
2023-03-28 11:14:26     _ended: true,
2023-03-28 11:14:26     res: IncomingMessage {
2023-03-28 11:14:26       _readableState: [ReadableState],
2023-03-28 11:14:26       _events: [Object: null prototype],
2023-03-28 11:14:26       _eventsCount: 4,
2023-03-28 11:14:26       _maxListeners: undefined,
2023-03-28 11:14:26       socket: [TLSSocket],
2023-03-28 11:14:26       httpVersionMajor: 1,
2023-03-28 11:14:26       httpVersionMinor: 1,
2023-03-28 11:14:26       httpVersion: '1.1',
2023-03-28 11:14:26       complete: true,
2023-03-28 11:14:26       rawHeaders: [Array],
2023-03-28 11:14:26       rawTrailers: [],
2023-03-28 11:14:26       aborted: false,
2023-03-28 11:14:26       upgrade: false,
2023-03-28 11:14:26       url: '',
2023-03-28 11:14:26       method: null,
2023-03-28 11:14:26       statusCode: 400,
2023-03-28 11:14:26       statusMessage: 'Bad Request',
2023-03-28 11:14:26       client: [TLSSocket],
2023-03-28 11:14:26       _consuming: false,
2023-03-28 11:14:26       _dumped: false,
2023-03-28 11:14:26       req: [Circular *1],
2023-03-28 11:14:26       responseUrl: 'https://upload.imagedelivery.net/ZBEqKIKgZgKrPlD3ay4FLg/432f6ebf-dd9f-4e1c-9d0a-28f42c0c6800',
2023-03-28 11:14:26       redirects: [],
2023-03-28 11:14:26       [Symbol(kCapture)]: false,
2023-03-28 11:14:26       [Symbol(kHeaders)]: [Object],
2023-03-28 11:14:26       [Symbol(kHeadersCount)]: 30,
2023-03-28 11:14:26       [Symbol(kTrailers)]: null,
2023-03-28 11:14:26       [Symbol(kTrailersCount)]: 0
2023-03-28 11:14:26     },
2023-03-28 11:14:26     aborted: false,
2023-03-28 11:14:26     timeoutCb: null,
2023-03-28 11:14:26     upgradeOrConnect: false,
2023-03-28 11:14:26     parser: null,
2023-03-28 11:14:26     maxHeadersCount: null,
2023-03-28 11:14:26     reusedSocket: false,
2023-03-28 11:14:26     host: 'upload.imagedelivery.net',
2023-03-28 11:14:26     protocol: 'https:',
2023-03-28 11:14:26     _redirectable: Writable {
2023-03-28 11:14:26       _writableState: [WritableState],
2023-03-28 11:14:26       _events: [Object: null prototype],
2023-03-28 11:14:26       _eventsCount: 3,
2023-03-28 11:14:26       _maxListeners: undefined,
2023-03-28 11:14:26       _options: [Object],
2023-03-28 11:14:26       _ended: true,
2023-03-28 11:14:26       _ending: true,
2023-03-28 11:14:26       _redirectCount: 0,
2023-03-28 11:14:26       _redirects: [],
2023-03-28 11:14:26       _requestBodyLength: 437499,
2023-03-28 11:14:26       _requestBodyBuffers: [],
2023-03-28 11:14:26       _onNativeResponse: [Function (anonymous)],
2023-03-28 11:14:26       _currentRequest: [Circular *1],
2023-03-28 11:14:26       _currentUrl: 'https://upload.imagedelivery.net/ZBEqKIKgZgKrPlD3ay4FLg/432f6ebf-dd9f-4e1c-9d0a-28f42c0c6800',
2023-03-28 11:14:26       [Symbol(kCapture)]: false
2023-03-28 11:14:26     },
2023-03-28 11:14:26     [Symbol(kCapture)]: false,
2023-03-28 11:14:26     [Symbol(kBytesWritten)]: 0,
2023-03-28 11:14:26     [Symbol(kEndCalled)]: true,
2023-03-28 11:14:26     [Symbol(kNeedDrain)]: true,
2023-03-28 11:14:26     [Symbol(corked)]: 0,
2023-03-28 11:14:26     [Symbol(kOutHeaders)]: [Object: null prototype] {
2023-03-28 11:14:26       accept: [Array],
2023-03-28 11:14:26       'content-type': [Array],
2023-03-28 11:14:26       'user-agent': [Array],
2023-03-28 11:14:26       'accept-encoding': [Array],
2023-03-28 11:14:26       host: [Array]
2023-03-28 11:14:26     },
2023-03-28 11:14:26     [Symbol(kUniqueHeaders)]: null
2023-03-28 11:14:26   },
2023-03-28 11:14:26   data: 'ERROR 5400: Bad request: incomplete multipart stream\n'

This topic was automatically closed after 15 days. New replies are no longer allowed.