[SOLVED]: Issues with adding support for asset uploads


#1

Hei,

I am working on support for uploading images to our javascript client squidex-client-manager. I have tried several things but have not gotten it to work yet.
I have read the instructions on Uploading assets via the API but I always end up with an error like the one below. Is there some example usage of CreateAssetAsync I could look at and then translate it to our client? Thanks.

Code

# https://github.com/scanf/squidex-client-manager/blob/master/src/index.js#L303-L308
const form = new FormData();
form.append('file', fs.createReadStream(assetUrl));
form.append('mimeType', 'jpeg');

const res = await this.squidexApi.apis.Assets
      .Assets_PostAsset({ app: this.appName }, { requestBody: form });

Error

   { ok: false,
     url: 'https://cloud.squidex.io/api/apps/my-blog-squidex/assets',
     status: 400,
     statusText: 'Bad Request',
     headers:
      { date: 'Thu, 15 Aug 2019 08:36:34 GMT',
        'content-type': 'application/json; charset=utf-8',
        'transfer-encoding': 'chunked',
        connection: 'close',
        'set-cookie':
         '__cfduid=d535a2070364e2170e1cc48a55a0a27f61565858194; expires=Fri, 14-Aug-20 08:36:34 GMT; path=/; domain=.squidex.io; HttpOnly; Secure',
        'expect-ct':
         'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
        server: 'cloudflare',
        'cf-ray': '5069d77379677664-ARN' },
     text:
      '{"message":"Cannot create asset.","details":["Can only upload one file, found 0 files."],"statusCode":400}',
     data:
      '{"message":"Cannot create asset.","details":["Can only upload one file, found 0 files."],"statusCode":400}',
     body:
      { message: 'Cannot create asset.',
        details: [Array],
        statusCode: 400 },
     obj:
      { message: 'Cannot create asset.',
        details: [Array],
        statusCode: 400 } } }

#2

Sorry, the content type header was set to JSON. It’s working when set to

          req.headers['Content-Type'] = 'multipart/form-data';