cap-js / attachments

The @cap-js/attachments package is a CDS plugin that provides out-of-the box asset storage and handling by using an aspect Attachments. It also provides a CAP-level, easy to use integration of the SAP Object Store.
Apache License 2.0
12 stars 4 forks source link

Cannot upload non-standard file types (e.g. .md files) #64

Open Zahlii opened 3 months ago

Zahlii commented 3 months ago
[odata] - PUT /unintegratedrequest-cockpit/UnintegratedDataRequests_attachments(up__ID=913b389d-77d4-4973-9c86-9ab108f6e3d4,ID=eed0a156-f3a8-4fe8-b2bd-da13f23e7aca,IsActiveEntity=false)/content 
[cds] - DeserializationError: Invalid value "undefined" in content-type header
    at RequestContentNegotiator.negotiate (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/format/RequestContentNegotiator.js:36:15)
    at DeserializingCommand.execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/DeserializingCommand.js:43:39)
    at CommandExecutor._execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:71:17)
    at /Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:81:18
    at PresetResponseHeadersCommand.execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/PresetResponseHeadersCommand.js:43:5)
    at CommandExecutor._execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:71:17)
    at /Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:81:18
    at LocaleNegotiatorCommand.execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/LocaleNegotiatorCommand.js:51:7)
    at CommandExecutor._execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:71:17)
    at /Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:81:18 {
  _rootCause: TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
      at new NodeError (node:internal/errors:399:5)
      at Function.from (node:buffer:339:9)
      at Function.parseContentTypeHeader (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/http/HttpHeader.js:14:59)
      at RequestContentNegotiator.negotiate (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/format/RequestContentNegotiator.js:33:22)
      at DeserializingCommand.execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/DeserializingCommand.js:43:39)
      at CommandExecutor._execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:71:17)
      at /Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:81:18
      at PresetResponseHeadersCommand.execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/PresetResponseHeadersCommand.js:43:5)
      at CommandExecutor._execute (/Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:71:17)
      at /Users/***/PycharmProjects/cockpit/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/CommandExecutor.js:81:18 {
    code: 'ERR_INVALID_ARG_TYPE'
  },
  id: '1955289',
  level: 'WARNING',
  timestamp: 1718184177894
}

With his request being send:

{
  "_priority": "High",
  "_resourceType": "xhr",
  "cache": {},
  "connection": "68280",
  "request": {
    "method": "PUT",
    "url": "http://localhost:4004/unintegratedrequest-cockpit/UnintegratedDataRequests_attachments(up__ID=913b389d-77d4-4973-9c86-9ab108f6e3d4,ID=efd48fab-f5db-499e-bc3d-d5debce40864,IsActiveEntity=false)/content",
    "httpVersion": "HTTP/1.1",
    "headers": [
      {
        "name": "Accept",
        "value": "application/json"
      },
      {
        "name": "Accept-Encoding",
        "value": "gzip, deflate, br, zstd"
      },
      {
        "name": "Accept-Language",
        "value": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,tr;q=0.6,es;q=0.5"
      },
      {
        "name": "Authorization",
        "value": "Basic STAwMTAwMDo="
      },
      {
        "name": "Connection",
        "value": "keep-alive"
      },
      {
        "name": "Content-Length",
        "value": "1961"
      },
      {
        "name": "DNT",
        "value": "1"
      },
      {
        "name": "Host",
        "value": "localhost:4004"
      },
      {
        "name": "Origin",
        "value": "http://localhost:4004"
      },
      {
        "name": "Referer",
        "value": "http://localhost:4004/fiori.html"
      },
      {
        "name": "Sec-Fetch-Dest",
        "value": "empty"
      },
      {
        "name": "Sec-Fetch-Mode",
        "value": "cors"
      },
      {
        "name": "Sec-Fetch-Site",
        "value": "same-origin"
      },
      {
        "name": "User-Agent",
        "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
      },
      {
        "name": "sec-ch-ua",
        "value": "\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\""
      },
      {
        "name": "sec-ch-ua-mobile",
        "value": "?0"
      },
      {
        "name": "sec-ch-ua-platform",
        "value": "\"macOS\""
      }
    ],
    "queryString": [],
    "headersSize": 1659,
    "bodySize": 0
  },
  "response": {
    "status": 400,
    "statusText": "Bad Request",
    "httpVersion": "HTTP/1.1",
    "headers": [
      {
        "name": "Connection",
        "value": "keep-alive"
      },
      {
        "name": "Content-Length",
        "value": "223"
      },
      {
        "name": "Date",
        "value": "Wed, 12 Jun 2024 09:24:33 GMT"
      },
      {
        "name": "Keep-Alive",
        "value": "timeout=5"
      },
      {
        "name": "OData-Version",
        "value": "4.0"
      },
      {
        "name": "X-Powered-By",
        "value": "Express"
      },
      {
        "name": "access-control-allow-origin",
        "value": "http://localhost:4004"
      },
      {
        "name": "content-type",
        "value": "application/json;odata.metadata=minimal"
      },
      {
        "name": "x-correlation-id",
        "value": "9f822bab-f850-4ffc-9514-c8c6ec0f7bf5"
      }
    ],
    "cookies": [],
    "content": {
      "size": 223,
      "mimeType": "application/json",
      "compression": 0
    },
    "redirectURL": "",
    "headersSize": 339,
    "bodySize": 223,
    "_transferSize": 562,
    "_error": null,
    "_content": {}
  },
  "serverIPAddress": "[::1]",
  "startedDateTime": "2024-06-12T09:24:33.136Z",
  "time": 7.392999948933721,
  "timings": {
    "blocked": 1.6189999473318457,
    "dns": -1,
    "ssl": -1,
    "connect": -1,
    "send": 0.14100000000000001,
    "wait": 4.957999984093011,
    "receive": 0.6750000175088644,
    "_blocked_queueing": 1.0479999473318458
  }
}
muskansethi1 commented 3 months ago

Hi @Zahlii,

I tested by uploading .md files in our sample application, and it works fine. When is this error being thrown?

Best Regards, Muskan