Skip to content

Commit 682d5ad

Browse files
committed
feat: support files
1 parent 10f149b commit 682d5ad

File tree

9 files changed

+221
-13
lines changed

9 files changed

+221
-13
lines changed

internal/store/store.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,16 @@ func readBody(req *http.Request) (map[string]any, error) {
112112
}
113113
err = json.Unmarshal(body, &resultMap)
114114
if err != nil {
115-
log.Fatalf("Error unmarshaling JSON: %v", err)
116-
return nil, err
115+
contentType := http.DetectContentType(body)
116+
isBinary := strings.HasPrefix(contentType, "image/") ||
117+
strings.HasPrefix(contentType, "video/") ||
118+
strings.HasPrefix(contentType, "audio/") ||
119+
contentType == "application/pdf" ||
120+
contentType == "application/octet-stream"
121+
if !isBinary {
122+
log.Printf("Error unmarshaling JSON: %v", err)
123+
return nil, err
124+
}
117125
}
118126
// Restore the request body for further use.
119127
req.Body = io.NopCloser(bytes.NewBuffer(body))

sdks/python/sample/data/scones.jpg

385 KB
Loading

sdks/python/sample/test-data/config/test-server-config.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,19 @@ endpoints:
55
source_type: http
66
source_port: 17080
77
health: /healthz
8+
- target_host: generativelanguage.googleapis.com
9+
target_port: 443
10+
source_port: 14530
11+
source_type: http
12+
target_type: https
13+
health: /healthz
14+
redact_request_headers:
15+
- X-Goog-Api-Key
16+
- Authorization
17+
- X-Goog-User-Project
18+
- User-Agent
19+
- X-Goog-Api-Client
20+
response_header_replacements:
21+
- header: X-Goog-Upload-Url
22+
regex: "^https://generativelanguage.googleapis.com/"
23+
replace: "http://localhost:14530/"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"recordID": "684fa789a83c255a1b4046883aeeaa5788e00d54e2a710b19c92ff9dfbe57df3",
3+
"interactions": [
4+
{
5+
"request": {
6+
"method": "POST",
7+
"url": "/upload/v1beta/files?upload_id=AAwnv3LPK9LarxPC5n6wRUV-HO-V5B0PImh3xDrc8DxZ5zWLPeB2gp4tFfV9UEKE_VBy4NgXy-0FMx6DhpAJ8__eUBHtSpmZw19AqV-d0d_Kcw\u0026upload_protocol=resumable",
8+
"request": "POST /upload/v1beta/files?upload_id=AAwnv3LPK9LarxPC5n6wRUV-HO-V5B0PImh3xDrc8DxZ5zWLPeB2gp4tFfV9UEKE_VBy4NgXy-0FMx6DhpAJ8__eUBHtSpmZw19AqV-d0d_Kcw\u0026upload_protocol=resumable HTTP/1.1",
9+
"headers": {
10+
"Accept": "*/*",
11+
"Accept-Encoding": "gzip, deflate",
12+
"Connection": "keep-alive",
13+
"Content-Length": "394671",
14+
"X-Goog-Upload-Command": "upload, finalize",
15+
"X-Goog-Upload-Offset": "0"
16+
},
17+
"bodySegments": [
18+
null
19+
],
20+
"previousRequest": "b4d6e60a9b97e7b98c63df9308728c5c88c0b40c398046772c63447b94608b4d",
21+
"serverAddress": "generativelanguage.googleapis.com",
22+
"port": 443,
23+
"protocol": "https"
24+
},
25+
"shaSum": "f63bd502f1ea60968b95fa4361861017b5dd9d55d77cbb0f595aaaff40acdcda",
26+
"response": {
27+
"statusCode": 200,
28+
"headers": {
29+
"Content-Length": "505",
30+
"Content-Type": "application/json; charset=UTF-8",
31+
"Date": "Tue, 16 Sep 2025 17:07:29 GMT",
32+
"Server": "UploadServer",
33+
"Vary": "Origin, X-Origin, Referer",
34+
"X-Goog-Upload-Status": "final",
35+
"X-Guploader-Uploadid": "AAwnv3LPK9LarxPC5n6wRUV-HO-V5B0PImh3xDrc8DxZ5zWLPeB2gp4tFfV9UEKE_VBy4NgXy-0FMx6DhpAJ8__eUBHtSpmZw19AqV-d0d_Kcw"
36+
},
37+
"bodySegments": [
38+
{
39+
"file": {
40+
"createTime": "2025-09-16T17:07:29.717643Z",
41+
"expirationTime": "2025-09-18T17:07:29.501913838Z",
42+
"mimeType": "image/jpeg",
43+
"name": "files/0kkj8nf2zgqq",
44+
"sha256Hash": "NzQ1MDVjZDc1OTJiMTBiYzJkNGU5YzRhYTQyOTg2NmRlNzNmNDAzZGIxMWVkZDk1YjViNDAwNGFlYTdlMTM3Ng==",
45+
"sizeBytes": "394671",
46+
"source": "UPLOADED",
47+
"state": "ACTIVE",
48+
"updateTime": "2025-09-16T17:07:29.717643Z",
49+
"uri": "https://generativelanguage.googleapis.com/v1beta/files/0kkj8nf2zgqq"
50+
}
51+
}
52+
]
53+
}
54+
}
55+
]
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"recordID": "97139812273710c0557f818dd79cb51326a639ce83aef69013473dddb0c76ce3",
3+
"interactions": [
4+
{
5+
"request": {
6+
"method": "POST",
7+
"url": "/upload/v1beta/files?upload_id=AAwnv3JuIG4MalPkarKR89aTKomHOXHoOu8hImQXUp_NlrDZPJ6QSkswH5Gx0fgqZXx_c-HlUED2aOhm5RrDn7uYRIEjFICy-0ltpjuw-g2ThQ\u0026upload_protocol=resumable",
8+
"request": "POST /upload/v1beta/files?upload_id=AAwnv3JuIG4MalPkarKR89aTKomHOXHoOu8hImQXUp_NlrDZPJ6QSkswH5Gx0fgqZXx_c-HlUED2aOhm5RrDn7uYRIEjFICy-0ltpjuw-g2ThQ\u0026upload_protocol=resumable HTTP/1.1",
9+
"headers": {
10+
"Accept": "*/*",
11+
"Accept-Encoding": "gzip, deflate",
12+
"Connection": "keep-alive",
13+
"Content-Length": "394671",
14+
"X-Goog-Upload-Command": "upload, finalize",
15+
"X-Goog-Upload-Offset": "0"
16+
},
17+
"bodySegments": [
18+
null
19+
],
20+
"previousRequest": "b4d6e60a9b97e7b98c63df9308728c5c88c0b40c398046772c63447b94608b4d",
21+
"serverAddress": "generativelanguage.googleapis.com",
22+
"port": 443,
23+
"protocol": "https"
24+
},
25+
"shaSum": "f7f17a7869a6d53c61fcd70426b43579fb9c113f2e9e09a8f1a81e57ff09ca05",
26+
"response": {
27+
"statusCode": 200,
28+
"headers": {
29+
"Content-Length": "505",
30+
"Content-Type": "application/json; charset=UTF-8",
31+
"Date": "Tue, 16 Sep 2025 17:06:34 GMT",
32+
"Server": "UploadServer",
33+
"Vary": "Origin, X-Origin, Referer",
34+
"X-Goog-Upload-Status": "final",
35+
"X-Guploader-Uploadid": "AAwnv3JuIG4MalPkarKR89aTKomHOXHoOu8hImQXUp_NlrDZPJ6QSkswH5Gx0fgqZXx_c-HlUED2aOhm5RrDn7uYRIEjFICy-0ltpjuw-g2ThQ"
36+
},
37+
"bodySegments": [
38+
{
39+
"file": {
40+
"createTime": "2025-09-16T17:06:34.492915Z",
41+
"expirationTime": "2025-09-18T17:06:34.125123298Z",
42+
"mimeType": "image/jpeg",
43+
"name": "files/heb0ucobclos",
44+
"sha256Hash": "NzQ1MDVjZDc1OTJiMTBiYzJkNGU5YzRhYTQyOTg2NmRlNzNmNDAzZGIxMWVkZDk1YjViNDAwNGFlYTdlMTM3Ng==",
45+
"sizeBytes": "394671",
46+
"source": "UPLOADED",
47+
"state": "ACTIVE",
48+
"updateTime": "2025-09-16T17:06:34.492915Z",
49+
"uri": "https://generativelanguage.googleapis.com/v1beta/files/heb0ucobclos"
50+
}
51+
}
52+
]
53+
}
54+
}
55+
]
56+
}

sdks/python/sample/test-data/recordings/models/folder1/folder2/python-sample-test_recursive_path.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@
2929
"Cache-Control": "max-age=0, private, must-revalidate",
3030
"Content-Encoding": "gzip",
3131
"Content-Language": "en-US",
32-
"Content-Security-Policy": "default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com github.githubassets.com edge.fullstory.com rs.fullstory.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com www.youtube-nocookie.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com images.ctfassets.net/8aevphvgewt8/; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com github.githubassets.com assets.ctfassets.net/8aevphvgewt8/ videos.ctfassets.net/8aevphvgewt8/; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/",
32+
"Content-Security-Policy": "default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com github.githubassets.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com edge.fullstory.com rs.fullstory.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com www.youtube-nocookie.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com images.ctfassets.net/8aevphvgewt8/; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com github.githubassets.com assets.ctfassets.net/8aevphvgewt8/ videos.ctfassets.net/8aevphvgewt8/; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/",
3333
"Content-Type": "text/html; charset=utf-8",
34-
"Date": "Mon, 15 Sep 2025 17:58:03 GMT",
35-
"Etag": "W/\"cd488b2ea2ae9702b6652dfcb4294b9f\"",
34+
"Date": "Tue, 16 Sep 2025 17:07:20 GMT",
35+
"Etag": "W/\"fbfb80938c80947c01efcd9b07d550e6\"",
3636
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
3737
"Server": "github.com",
38-
"Set-Cookie": "_gh_sess=3YXTN2Kn9fZ548MFymDvF4bmU3CVT1fhBeYO4rhAseW2l4rkmT0wzpD6sxgKPmt6uiXpcanTYQoSk0His54Z5ZVw1bPeaynC5BS5XzhvbMHfO4jT%2Ffg7udqglbBw1lmCRyr34q2WlFb%2F%2BM5aF3ErLwjPQUIHzxN1MH12fLFOxbh919Qvxs%2FEc%2FEdCQkb6a5wSvhYSihZXyGtDSQkRN%2FtE74aZZzOhn9hhHo68SeDmE47VCWIRm%2Bk1MGP3C6YiXwHjHF3T0%2Bu4OupJqUgKvKkbw%3D%3D--q7RzlJy371g%2FhXQu--2ZImD096TJjWHHRIqjJi%2Bg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax, _octo=GH1.1.1334543195.1757959087; Path=/; Domain=github.com; Expires=Tue, 15 Sep 2026 17:58:07 GMT; Secure; SameSite=Lax, logged_in=no; Path=/; Domain=github.com; Expires=Tue, 15 Sep 2026 17:58:07 GMT; HttpOnly; Secure; SameSite=Lax",
38+
"Set-Cookie": "_gh_sess=5uG%2FiPcnYWHHlvxfs4Jg5qhwVdzXE9yF8Vny6wIYl8DlBINY0uD22%2Fa9GyjhTLc8kOv7pJyW%2FmQ1i00xnIHt6qRJnmXFlsPo%2BmfSKrSMcZP77525zGMvcYc6XyzzJixzr5GB4bsOTLNmArmPEMFeLqTFQSEzDPsLdFkJdcm1tshI11cFcOGhX83qmCHn1htpVVDD9xAUU64YzMud2jrxAjOdg2hO1xLfe3J1x%2BjNJhmh8rnakdwZQCmIXzpX3R6XyRitDDk%2F4Y%2FMvUME8dkiRg%3D%3D--NNWFRZ4hSwlY9waY--iCcRp2MPy2pzsEGvoWJ14A%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax, _octo=GH1.1.1388852089.1758042448; Path=/; Domain=github.com; Expires=Wed, 16 Sep 2026 17:07:28 GMT; Secure; SameSite=Lax, logged_in=no; Path=/; Domain=github.com; Expires=Wed, 16 Sep 2026 17:07:28 GMT; HttpOnly; Secure; SameSite=Lax",
3939
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
4040
"Vary": "X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With, Accept-Language,Accept-Encoding, Accept, X-Requested-With",
4141
"X-Content-Type-Options": "nosniff",
4242
"X-Frame-Options": "deny",
43-
"X-Github-Request-Id": "D872:2A9986:920E617:96857F7:68C853AF",
43+
"X-Github-Request-Id": "DA2B:1A28F1:44A2F33:462F309:68C99950",
4444
"X-Xss-Protection": "0"
4545
}
4646
}

0 commit comments

Comments
 (0)