# 500 error when including a file

**URL:** <https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512>\
**Category:** Gemini API\
**Tags:** model, api\
**Created:** [September 16, 2024, 10:54pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512 "2024-09-16T22:54:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikhaeel](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mikhaeel/32/22490_2.png) [@Mikhaeel](https://discuss.ai.google.dev/u/Mikhaeel)\
**Post date:** [September 16, 2024, 10:54pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/1 "2024-09-16T22:54:28Z")

</div>

Hi,

I consistently receive a 500 error when I include a file in my API call. I’ve tested every available model and they all return the error. The “fileUri” is correct and exists. I’ve doubled checked it by listing the files stored in my Gemini uploads.

Here’s my cURL request.

```auto
curl --location 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key={mykey}' \
--header 'Content-Type: application/json' \
--data '{
  "contents": [
    {
      "parts": [
        {
          "text": "What is this picture?"
        },
        {
          "fileData": {
            "mime_type": "image/jpeg",
            "fileUri": "https://generativelanguage.googleapis.com/v1beta/files/6ex7hs0zb9kp"
          }
        }
      ]
    }
  ]
}'

```

I need to get this running for a project, but I can’t seem to find any solution online.

Thanks,  
Mikhaeel

---

<div class="post-metadata">

**Author:** ![GUNAND\_MAYANGLAMBAM](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/gunand_mayanglambam/32/4964_2.png) [@GUNAND\_MAYANGLAMBAM](https://discuss.ai.google.dev/u/GUNAND_MAYANGLAMBAM)\
**Post date:** [September 17, 2024, 4:32am UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/2 "2024-09-17T04:32:03Z")

</div>

Hi @Mikhaeel ,

Could you try with the below cURL request.

```auto
curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "contents": [
    {
      "parts": [
        {
          "text": "What is this picture?"
        },
        {
          "fileData": {
            "fileUri": "https://generativelanguage.googleapis.com/v1beta/files/29ar4fcyhnty",
            "mimeType": "image/jpeg"
          }
        }
      ],
      "role": "user"
    }
  ]
}'

```

---

<div class="post-metadata">

**Author:** ![Mikhaeel](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mikhaeel/32/22490_2.png) [@Mikhaeel](https://discuss.ai.google.dev/u/Mikhaeel)\
**Post date:** [September 17, 2024, 11:50am UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/4 "2024-09-17T11:50:15Z")

</div>

Hey @GUNAND_MAYANGLAMBAM,

Thanks for your reply.

Your cURL request returns a 403 Forbidden error. I assume that’s because I don’t have access to your fileUri.

---

<div class="post-metadata">

**Author:** ![GUNAND\_MAYANGLAMBAM](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/gunand_mayanglambam/32/4964_2.png) [@GUNAND\_MAYANGLAMBAM](https://discuss.ai.google.dev/u/GUNAND_MAYANGLAMBAM)\
**Post date:** [September 17, 2024, 11:55am UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/5 "2024-09-17T11:55:01Z")

</div>

Yes @Mikhaeel , you need to replace it with your `fileUri`. I have just provided you with a sample request.

---

<div class="post-metadata">

**Author:** ![Mikhaeel](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mikhaeel/32/22490_2.png) [@Mikhaeel](https://discuss.ai.google.dev/u/Mikhaeel)\
**Post date:** [September 17, 2024, 12:01pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/6 "2024-09-17T12:01:50Z")

</div>

Oh my mistake.

I tested your request with my fileUri, but I still receive the 500 error.

---

<div class="post-metadata">

**Author:** ![Mikhaeel](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mikhaeel/32/22490_2.png) [@Mikhaeel](https://discuss.ai.google.dev/u/Mikhaeel)\
**Post date:** [September 17, 2024, 12:06pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/7 "2024-09-17T12:06:49Z")

</div>

@GUNAND_MAYANGLAMBAM Would you mind sharing a cURL request for uploading a file. Maybe I’m doing something wrong when uploading my file URI.

---

<div class="post-metadata">

**Author:** ![GUNAND\_MAYANGLAMBAM](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/gunand_mayanglambam/32/4964_2.png) [@GUNAND\_MAYANGLAMBAM](https://discuss.ai.google.dev/u/GUNAND_MAYANGLAMBAM)\
**Post date:** [September 17, 2024, 12:11pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/8 "2024-09-17T12:11:00Z")

</div>

Try below request for uploading a file:

!wget “[https://storage.googleapis.com/generativeai-downloads/images/jetpack.jpg](https://storage.googleapis.com/generativeai-downloads/images/jetpack.jpg)”

```auto
curl -X POST "https://generativelanguage.googleapis.com/upload/v1beta/files?key=$GOOGLE_API_KEY" \

-H "Content-Type: multipart/form-data" \

-F "file=@jetpack.jpg;type=image/jpeg"
```

---

<div class="post-metadata">

**Author:** ![Mikhaeel](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mikhaeel/32/22490_2.png) [@Mikhaeel](https://discuss.ai.google.dev/u/Mikhaeel)\
**Post date:** [September 17, 2024, 12:18pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/9 "2024-09-17T12:18:58Z")

</div>

How would this request look if I was uploading the raw base64 encoded file data?

---

<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:** [September 17, 2024, 2:08pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/11 "2024-09-17T14:08:51Z")

</div>

How are you doing it?  
The error roughly sounds like it could be expecting a jpg file, but not actually finding one there.

I’ve done the uploads with something like this:

```auto
file=blue-square.png
file64=`base64 ${file}`

body=$(
    cat <<EOF > /tmp/file-upload-2.txt
--separator-1719347666612
Content-Type: application/json; charset=UTF-8

{
}

--separator-1719347666612
Content-Type: image/png
Content-Transfer-Encoding: base64

${file64}
--separator-1719347666612--
EOF
)

curl \
  -X POST \
  -H "Content-Type: multipart/related; boundary=separator-1719347666612" \
  -H "X-Goog-Upload-Protocol: multipart" \
  --data-binary @/tmp/file-upload-2.txt \
  "https://generativelanguage.googleapis.com/upload/v1beta/files?key=${API_KEY}"

```

Which still uses an intermediary temp file. (Which in this case is a little silly, I’ll admit, since it is reading it in from a file first, but I was doing this to specifically test the base64 case.)

---

<div class="post-metadata">

**Author:** ![Mikhaeel](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mikhaeel/32/22490_2.png) [@Mikhaeel](https://discuss.ai.google.dev/u/Mikhaeel)\
**Post date:** [September 17, 2024, 7:18pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/12 "2024-09-17T19:18:53Z")

</div>

I was doing something wrong in my request. I was putting the base64 data in the body of my request instead of attaching the actual file.

Seems to be working fine now.

Thanks for everyone’s help!

---

<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:** [September 17, 2024, 7:23pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/13 "2024-09-17T19:23:24Z")

</div>

Glad you figured this out and you’re back on track!

---

<div class="post-metadata">

**Author:** ![Mikhaeel](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mikhaeel/32/22490_2.png) [@Mikhaeel](https://discuss.ai.google.dev/u/Mikhaeel)\
**Post date:** [September 17, 2024, 8:37pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/14 "2024-09-17T20:37:08Z")

</div>

Thanks, I appreciate your time!

---

<div class="post-metadata">

**Author:** ![OrangiaNebula](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/orangianebula/32/480_2.png) [@OrangiaNebula](https://discuss.ai.google.dev/u/OrangiaNebula)\
**Post date:** [September 17, 2024, 8:50pm UTC](https://discuss.ai.google.dev/t/500-error-when-including-a-file/39512/15 "2024-09-17T20:50:13Z")

</div>

> [@Mikhaeel](#):
>
> putting the base64 data in the body of my request

The inline data request supports that. It is not as versatile as the file API, but is also useful for specific scenarios.
