How to Download an Image File by File ID in Azure Assistant using JavaScript?

Su Myat Hlaing 150 Reputation points
2024-08-23T02:09:19.5133333+00:00

Hello,

I've been working with Azure Assistant OpenAI and successfully retrieved the fileId for image files using the listMessages method. However, I'm now trying to figure out how to download the image file using this fileId in JavaScript.

I followed the example provided in the documentation and the SDK reference. While I can obtain the fileId for images, I'm encountering an issue when trying to download the actual image file. It seems that I can’t download the file directly using the fileId; instead, I need a file link.

Could someone guide me on how to obtain this file link or the correct method to download an image file using the fileId in JavaScript? Any guidance or code examples would be greatly appreciated.

Thank you in advance!

const runMessages = await assistantsClient.listMessages(assistantThread.id);
for (const runMessageDatum of runMessages.data) {
  for (const item of runMessageDatum.content) {
    if (item.type === "text") {
      console.log(item.text.value);
    } else if (item.type === "image_file") {
      console.log(item.imageFile.fileId);
    }
  }
}

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,891 questions
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. Vahid Ghafarpour 21,085 Reputation points
    2024-08-23T02:40:26.4733333+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    I'd use the getImageFile() method of MessageImageFileDetails

    https://azuresdkdocs.blob.core.windows.net/$web/java/azure-ai-openai-assistants/1.0.0-beta.3/com/azure/ai/openai/assistants/models/MessageImageFileContent.html#getImageFile()

    https://learn.microsoft.com/en-us/javascript/api/@azure/openai-assistants/messageimagefiledetails?view=azure-node-preview#@azure-openai-assistants-messageimagefiledetails-fileid

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **


  2. Su Myat Hlaing 150 Reputation points
    2024-09-10T07:24:01.9666667+00:00

    I successfully downloaded the file using the solution provided in this GitHub issue.

    0 comments No comments

  3. Su Myat Hlaing 150 Reputation points
    2024-09-10T07:26:01.2933333+00:00

    I successfully downloaded the file. https://github.com/Azure/azure-sdk-for-js/issues/30968

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.