MCPcopy Create free account
hub / github.com/rilldata/rill / UploadMultipartFile

Method UploadMultipartFile

runtime/server/repos.go:213–262  ·  view source on GitHub ↗

UploadMultipartFile implements the same functionality as PutFile, but for multipart HTTP upload. It's mounted only on as a REST API and enables upload of large files (such as data files).

(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

211// UploadMultipartFile implements the same functionality as PutFile, but for multipart HTTP upload.
212// It's mounted only on as a REST API and enables upload of large files (such as data files).
213func (s *Server) UploadMultipartFile(w http.ResponseWriter, req *http.Request) {
214 ctx := req.Context()
215 instanceID := req.PathValue("instance_id")
216 path := req.PathValue("path")
217
218 if !auth.GetClaims(req.Context(), instanceID).Can(runtime.EditRepo) {
219 http.Error(w, "action not allowed", http.StatusUnauthorized)
220 return
221 }
222
223 if err := req.ParseForm(); err != nil {
224 http.Error(w, fmt.Sprintf("failed to parse request: %s", err), http.StatusBadRequest)
225 return
226 }
227
228 f, _, err := req.FormFile("file")
229 if err != nil {
230 http.Error(w, fmt.Sprintf("failed to parse file in request: %s", err), http.StatusBadRequest)
231 return
232 }
233 defer f.Close()
234
235 if path == "" {
236 http.Error(w, "must have a path to file", http.StatusBadRequest)
237 return
238 }
239
240 observability.AddRequestAttributes(ctx, attribute.String("args.instance_id", instanceID), attribute.String("args.path", path))
241
242 s.addInstanceRequestAttributes(ctx, instanceID)
243
244 err = s.runtime.PutFile(ctx, instanceID, path, f, true, false)
245 if err != nil {
246 http.Error(w, fmt.Sprintf("failed to write file: %s", err), http.StatusBadRequest)
247 return
248 }
249
250 res, err := protojson.Marshal(&runtimev1.PutFileResponse{})
251 if err != nil {
252 http.Error(w, fmt.Sprintf("failed to serialize response: %s", err), http.StatusInternalServerError)
253 return
254 }
255
256 w.Header().Set("Content-Type", "application/json")
257 _, err = w.Write(res)
258 if err != nil {
259 http.Error(w, fmt.Sprintf("failed to write response data: %s", err), http.StatusInternalServerError)
260 return
261 }
262}

Callers

nothing calls this directly

Calls 11

GetClaimsFunction · 0.92
AddRequestAttributesFunction · 0.92
CanMethod · 0.80
ContextMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65
PutFileMethod · 0.65
ErrorMethod · 0.45
SetMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected