Status error 400 while uploading file

31 views
Skip to first unread message

Alfredo Alexander

unread,
Apr 14, 2025, 5:31:04 AM4/14/25
to DSpace Technical Support
Hi.
I have this code:
const fileBody = `------${uuid}
  Content-Disposition: form-data; name="file"; filename=${file.name}
  Content-Type: application/pdf
 
  ${newFile}
  ------${uuid}--`;

  const fileUploadResponse = await fetch(formUrl, {
    method: "POST",
    headers: {
      Authorization: bearerToken ?? "",
      Cookie: xsrfCookie,
      "Content-Type": `multipart/form-data; boundary=------${uuid}`,
      "X-XSRF-TOKEN": csrfToken ?? "",
    },
    body: fileBody,
  });



I'm trying to upload the file to my submission. I have successfully added the traditionalpageone and the license items, but I can't upload the file.
I get this missage: Response { status: 400,
  statusText: '',
  headers:
   Headers { date: 'Mon, 14 Apr 2025 09:23:04 GMT',
     server: 'Apache',
     vary: 'Origin,Access-Control-Request-Method,Access-Control-Request-Headers',
     'content-language': 'ca,es,en',
     'x-content-type-options': 'nosniff',
     'x-xss-protection': '0',
     'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
     pragma: 'no-cache',
     expires: '0',
     'strict-transport-security': 'max-age=31536000 ; includeSubDomains',
     'x-frame-options': 'DENY',
     'content-type': 'application/problem+json;charset=UTF-8',
     'content-security-policy': "frame-ancestors 'self';",
     'access-control-expose-headers':
      'Authorization, expires, Location, Content-Disposition, WWW-Authenticate, Set-Cookie, X-Requested-With, DSPACE-XSRF-TOKEN',
     'access-control-allow-origin': 'https://new-bcnroc.metricsalad.com',
     'access-control-allow-credentials': 'true',
     'access-control-allow-methods': 'PUT, GET, POST, DELETE, OPTIONS, PATCH',
     connection: 'close',
     'transfer-encoding': 'chunked' },
  body: ReadableStream { locked: false, state: 'readable', supportsBYOB: true },
  bodyUsed: false,
  ok: false,
  redirected: false,
  type: 'basic',
  url: 'https://api-new-bcnroc.metricsalad.com/api/submission/workspaceitems/143964' }

Can you help me to solve it?

DSpace Technical Support

unread,
Apr 21, 2025, 10:59:12 AM4/21/25
to DSpace Technical Support
Hi,

I'd recommend checking the DSpace backend logs to see if it has more information about the cause of the 400 error.  A 400 error is a "Bad Request", but sometimes the easiest way to debug it is to get the detailed error message from the backend.

If nothing appears in the backend logs, then you could also temporarily turn on debug mode for the REST API, so that a more detailed error is sent back in the 400 response.  See the troubleshooting guide for details on how to enable debug mode: https://wiki.lyrasis.org/display/DSPACE/Troubleshoot+an+error#Troubleshootanerror-3.DebugmodefortheRESTAPI(ifnecessary)

Tim

Reply all
Reply to author
Forward
0 new messages