MCPcopy
hub / github.com/MiniMax-AI/cli / run

Function run

src/commands/file/upload.ts:28–77  ·  view source on GitHub ↗
(config: Config, flags: GlobalFlags)

Source from the content-addressed store, hash-verified

26 'mmx file upload --file image.png --purpose vision',
27 ],
28 async run(config: Config, flags: GlobalFlags) {
29 let filePath = flags.file as string | undefined;
30
31 if (!filePath) {
32 if (isInteractive({ nonInteractive: config.nonInteractive })) {
33 filePath = await promptText({ message: 'Enter file path:' });
34 if (!filePath) {
35 process.stderr.write('Upload cancelled.\n');
36 process.exit(1);
37 }
38 } else {
39 failIfMissing('file', 'mmx file upload --file <path>');
40 }
41 }
42
43 const fullPath = resolve(filePath);
44 if (!existsSync(fullPath)) {
45 throw new CLIError(`File not found: ${fullPath}`, ExitCode.USAGE);
46 }
47
48 const purpose = (flags.purpose as string) || 'retrieval';
49 const format = detectOutputFormat(config.output);
50
51 if (config.dryRun) {
52 process.stdout.write(formatOutput({ request: { file: fullPath, purpose } }, format) + '\n');
53 return;
54 }
55
56 const formData = new FormData();
57 // Read file using Node.js fs/promises (compatible with both Node and Bun)
58 const fileData = await readFile(fullPath);
59 const fileName = basename(fullPath);
60 const fileBlob = new Blob([fileData]);
61 formData.append('file', fileBlob, fileName);
62 formData.append('purpose', purpose);
63
64 const url = fileUploadEndpoint(config.baseUrl);
65 const response = await requestJson<FileUploadResponse>(config, {
66 url,
67 method: 'POST',
68 body: formData,
69 });
70
71 if (config.quiet) {
72 process.stdout.write(response.file.file_id + '\n');
73 return;
74 }
75
76 process.stdout.write(formatOutput(response.file, format) + '\n');
77 },
78});

Callers

nothing calls this directly

Calls 6

isInteractiveFunction · 0.90
promptTextFunction · 0.90
failIfMissingFunction · 0.90
detectOutputFormatFunction · 0.90
formatOutputFunction · 0.90
fileUploadEndpointFunction · 0.90

Tested by

no test coverage detected