I am blocked on what seems like a very simple problem - setting the displayName upon upload in my AI Studio app (using the build capability and Gemini JS SDK).
Here’s the two functions of the app:
- Upload the file and review the Files API response
- Show all files in persistent storage along with all data in the Files API response to the list call
Here is the code that AI studio wrote to handle the upload portion:
try {
const response = await ai.files.upload({
file: selectedFile,
displayName: displayName || undefined,
mimeType: selectedFile.type,
});
showModal('Upload Successful', response);
setSelectedFile(null);
setDisplayName('');
(e.target as HTMLFormElement).reset();
fetchFiles(); // Refresh file list
} catch (error) {
console.error("Error uploading file:", error);
setUploadError(error instanceof Error ? error.message : String(error));
} finally {
setIsUploading(false);
}
AI studio reports that there are inconsistencies in the API implementation and it/I have tried multiple attempts to restructure this call, and use different methods to get the displayName set upon upload.
I have validated this using Python and know it works, but there seems to be a bug or inconsistent implementation with the JS SDK.
Can you please assist and either 1) confirm that it’s a bug or 2) not supported or 3) provide a code block to show how to do it?