@@ -44,6 +44,16 @@ func (r *AssetService) Download(ctx context.Context, body AssetDownloadParams, o
4444 return
4545}
4646
47+ // Upload a file to a temporary location. Supports JSON body with base64 `content`
48+ // field, or multipart/form-data with `file` field. Returns a local file URL that
49+ // can be used when sending messages with attachments.
50+ func (r * AssetService ) Upload (ctx context.Context , body AssetUploadParams , opts ... option.RequestOption ) (res * AssetUploadResponse , err error ) {
51+ opts = slices .Concat (r .Options , opts )
52+ path := "v1/assets/upload"
53+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodPost , path , body , & res , opts ... )
54+ return
55+ }
56+
4757type AssetDownloadResponse struct {
4858 // Error message if the download failed.
4959 Error string `json:"error"`
@@ -64,6 +74,47 @@ func (r *AssetDownloadResponse) UnmarshalJSON(data []byte) error {
6474 return apijson .UnmarshalRoot (data , r )
6575}
6676
77+ type AssetUploadResponse struct {
78+ // Duration in seconds (audio/videos)
79+ Duration float64 `json:"duration"`
80+ // Error message if upload failed
81+ Error string `json:"error"`
82+ // Resolved filename
83+ FileName string `json:"fileName"`
84+ // File size in bytes
85+ FileSize float64 `json:"fileSize"`
86+ // Height in pixels (images/videos)
87+ Height float64 `json:"height"`
88+ // Detected or provided MIME type
89+ MimeType string `json:"mimeType"`
90+ // Local file URL (file://) for the uploaded asset
91+ SrcURL string `json:"srcURL"`
92+ // Unique upload ID for this asset
93+ UploadID string `json:"uploadID"`
94+ // Width in pixels (images/videos)
95+ Width float64 `json:"width"`
96+ // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
97+ JSON struct {
98+ Duration respjson.Field
99+ Error respjson.Field
100+ FileName respjson.Field
101+ FileSize respjson.Field
102+ Height respjson.Field
103+ MimeType respjson.Field
104+ SrcURL respjson.Field
105+ UploadID respjson.Field
106+ Width respjson.Field
107+ ExtraFields map [string ]respjson.Field
108+ raw string
109+ } `json:"-"`
110+ }
111+
112+ // Returns the unmodified JSON received from the API
113+ func (r AssetUploadResponse ) RawJSON () string { return r .JSON .raw }
114+ func (r * AssetUploadResponse ) UnmarshalJSON (data []byte ) error {
115+ return apijson .UnmarshalRoot (data , r )
116+ }
117+
67118type AssetDownloadParams struct {
68119 // Matrix content URL (mxc:// or localmxc://) for the asset to download.
69120 URL string `json:"url,required"`
@@ -77,3 +128,21 @@ func (r AssetDownloadParams) MarshalJSON() (data []byte, err error) {
77128func (r * AssetDownloadParams ) UnmarshalJSON (data []byte ) error {
78129 return apijson .UnmarshalRoot (data , r )
79130}
131+
132+ type AssetUploadParams struct {
133+ // Base64-encoded file content (max ~500MB decoded)
134+ Content string `json:"content,required"`
135+ // Original filename. Generated if omitted
136+ FileName param.Opt [string ] `json:"fileName,omitzero"`
137+ // MIME type. Auto-detected from magic bytes if omitted
138+ MimeType param.Opt [string ] `json:"mimeType,omitzero"`
139+ paramObj
140+ }
141+
142+ func (r AssetUploadParams ) MarshalJSON () (data []byte , err error ) {
143+ type shadow AssetUploadParams
144+ return param .MarshalObject (r , (* shadow )(& r ))
145+ }
146+ func (r * AssetUploadParams ) UnmarshalJSON (data []byte ) error {
147+ return apijson .UnmarshalRoot (data , r )
148+ }
0 commit comments