Files API issues with base64images

Hi there.
So I have a swift app that is sending png images to my backend in base64 encoded string format.

I’m trying to pass these into the files api which would then get used by my assistant.

https://platform.openai.com/docs/api-reference/files/create

Im having troubles passing the encoded strings.
I get this error

BadRequestError: 400 The browser (or proxy) sent a request that this server could not understand.
at APIError.generate (/home/ec2-user/Seda-Prod/Backend/node_modules/openai/error.js:45:20)
at OpenAI.makeStatusError (/home/ec2-user/Seda-Prod/Backend/node_modules/openai/core.js:275:33)
at OpenAI.makeRequest (/home/ec2-user/Seda-Prod/Backend/node_modules/openai/core.js:318:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.uploadImage (/home/ec2-user/Seda-Prod/Backend/src/api/services/OpenAIServices.js:98:26)
at async post_ai_query (/home/ec2-user/Seda-Prod/Backend/src/api/controllers/ai_queryController.js:73:22) {
status: 400,
headers: {
‘access-control-allow-origin’: ‘*’,
‘alt-svc’: ‘h3=“:443”; ma=86400’,
‘cf-cache-status’: ‘DYNAMIC’,
‘cf-ray’: ‘8d2c144b7c86824a-IAD’,
connection: ‘keep-alive’,
‘content-length’: ‘180’,
‘content-type’: ‘application/json’,
date: ‘Tue, 15 Oct 2024 01:36:38 GMT’,
‘openai-organization’: ‘user-prt4m5mdaifwd91vfkjr9io9’,
‘openai-processing-ms’: ‘268’,
‘openai-version’: ‘2020-10-01’,
server: ‘cloudflare’,
‘set-cookie’: ‘__cf_bm=1Sz.Ba1khpHXHYSVYW6UiaURzsE59bNuXHvgMlbVBtg-1728956198-1.0.1.1-KOKbV5huhox.JbQPsz3aKFo471n312XGR8eyM1J6nE5KRAznLs5YkwdGSPEFv4RY7zzN25O9itH5q2McjuNizg; path=/; expires=Tue, 15-Oct-24 02:06:38 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None, _cfuvid=KX_JzBZ4AMd1vs08vuIWVZkP8pm5h3welFM_k1Ofu2A-1728956198154-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None’,
‘strict-transport-security’: ‘max-age=31536000; includeSubDomains; preload’,
‘x-content-type-options’: ‘nosniff’,
‘x-request-id’: ‘req_9eb10ffd334da795c59cba554efb2b41’
},
request_id: ‘req_9eb10ffd334da795c59cba554efb2b41’,
error: {
message: ‘The browser (or proxy) sent a request that this server could not understand.’,
type: ‘server_error’,
param: null,
code: null
},
code: null,
param: null,
type: ‘server_error’
}

Can we get support for directly passing base64 encoded string for the files api for pngs?

Are you wanting “feature request” for something that doesn’t exist?

Or, are you wanting to know how to upload an image file?

The API documentation is kind of dumb, in that it says you upload a file object - and that the endpoint returns the file object.

In a way, the files endpoint does accept base64, because what you must send is a multipart/form-data POST https request, where the file is MIME attachment of type image/png, with file name. Knowing this, your Google search for some code will have answers.

Part of the “form” is to send the purpose of the file, also.