# Am I using the FileData / Uri part wrong?

**URL:** <https://discuss.ai.google.dev/t/am-i-using-the-filedata-uri-part-wrong/1494>\
**Category:** Gemini API\
**Tags:** api\
**Created:** [May 9, 2024, 5:41pm UTC](https://discuss.ai.google.dev/t/am-i-using-the-filedata-uri-part-wrong/1494 "2024-05-09T17:41:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_M](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mr_m/32/1389_2.png) [@Mr\_M](https://discuss.ai.google.dev/u/Mr_M)\
**Post date:** [May 9, 2024, 5:41pm UTC](https://discuss.ai.google.dev/t/am-i-using-the-filedata-uri-part-wrong/1494/1 "2024-05-09T17:41:07Z")

</div>

I have some reference materials on a website - a .txt file. Looks like I can have the API reference it, though I couldn’t find much documentation on it. The API doesn’t seem to like my request.

```auto
{"contents": [{
    "parts": [
      {
        "text": "USER QUERY HERE",
        "fileData": {
          "mimeType": "text/plain",
          "fileUri": "http://example.com/filename.txt"
        }
      }
    ]
  }

```

First of all, does the JSON look correct? If so, is the text file just included in the request and the chatbot can just see anything in there, as if it were a part of the user text? Would this be different than just including it in the main content parts ?

Here is the response I get:

```auto
{
  "error": {
    "code": 400,
    "message": "* GenerateContentRequest.contents: contents is not specified\n",
    "status": "INVALID_ARGUMENT"
  }
}

```

---

<div class="post-metadata">

**Author:** ![afirstenberg](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/afirstenberg/32/202_2.png) [@afirstenberg](https://discuss.ai.google.dev/u/afirstenberg)\
**Post date:** [May 9, 2024, 7:19pm UTC](https://discuss.ai.google.dev/t/am-i-using-the-filedata-uri-part-wrong/1494/2 "2024-05-09T19:19:15Z")

</div>

The problem is that _each_ part can be _either_ a `text` part _or_ a `fileData` part or `inlineData` _or_ one of the function parts. See [https://ai.google.dev/api/rest/v1beta/Content#Part](https://ai.google.dev/api/rest/v1beta/Content#Part) for details.  
You’re allowed multiple parts - they just need to be different kinds in each. So that would look more like:

```auto
{"contents": [{
    "parts": [
      {
        "text": "USER QUERY HERE"
      },{
        "fileData": {
          "mimeType": "text/plain",
          "fileUri": "http://example.com/filename.txt"
        }
      }
    ]
  }

```

The second problem, however, is that although “text/plain” is _probably_ a valid type (Vertex AI lists it as valid), you can’t import it from an external URL. The URL must be one that was provided when you uploaded the file using the File API.

When reading it in, it will treat it just like other parts in the prompt.

---

<div class="post-metadata">

**Author:** ![Mr\_M](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mr_m/32/1389_2.png) [@Mr\_M](https://discuss.ai.google.dev/u/Mr_M)\
**Post date:** [May 9, 2024, 8:56pm UTC](https://discuss.ai.google.dev/t/am-i-using-the-filedata-uri-part-wrong/1494/3 "2024-05-09T20:56:10Z")

</div>

Wonderful - I think I tried it that way too but it also didn’t work. Perhaps it is related to your comment about needing to upload a file first. I haven’t tried that - I thought I could just reference my own URL links.

As for “reading it in and treating it like other parts in the prompt” - what would be the benefit, then? I already “pull in” text parts based on the user query as if it were an external file (that way i don’t always send up the entire reference doc). Is there a benefit to uploading a file vs. including it inside one of the text parts? Sure, a benefit would be that you don’t have to send it up every time but as I said, I already parse the user input so as to not load it if not necessary.

Is there a benefit such as not using as many tokens? Guess I’m just trying to figure out if my current solution is fine without having to also upload a file somewhere and then reference it.

---

<div class="post-metadata">

**Author:** ![afirstenberg](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/afirstenberg/32/202_2.png) [@afirstenberg](https://discuss.ai.google.dev/u/afirstenberg)\
**Post date:** [May 10, 2024, 2:43am UTC](https://discuss.ai.google.dev/t/am-i-using-the-filedata-uri-part-wrong/1494/4 "2024-05-10T02:43:42Z")

</div>

The benefits are

- UX management (ie - if the user uploads a file, you can treat it as a file, and not special case some files but not others)
- network latency (ie - if you have it in the File API, then you don’t have to re-send it as a text part every step of the conversation)

There is no benefit in processing speed or number of tokens used.

> [@Mr\_M](#):
>
> I thought I could just reference my own URL links.

Nope. If you want to get something from an external URL you need to fetch the content and store it in the File API yourself.

---

<div class="post-metadata">

**Author:** ![Mr\_M](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mr_m/32/1389_2.png) [@Mr\_M](https://discuss.ai.google.dev/u/Mr_M)\
**Post date:** [May 10, 2024, 6:01pm UTC](https://discuss.ai.google.dev/t/am-i-using-the-filedata-uri-part-wrong/1494/6 "2024-05-10T18:01:37Z")

</div>

Was very helpful. Thanks for your responses - and for answering all sub-questions within my questions 🙂
