MCPcopy Create free account
hub / github.com/devld/go-drive / ReadRequestBodyToTempFile

Function ReadRequestBodyToTempFile

server/utils.go:232–250  ·  view source on GitHub ↗
(c *gin.Context, tempDir string)

Source from the content-addressed store, hash-verified

230}
231
232func ReadRequestBodyToTempFile(c *gin.Context, tempDir string) (*utils.TempFile, int64, error) {
233 size := utils.ToInt64(c.GetHeader("Content-Length"), -1)
234 file, e := drive_util.CopyReaderToTempFile(task.NewTaskContext(c.Request.Context()), c.Request.Body, tempDir)
235 if e != nil {
236 return nil, -1, e
237 }
238 stat, e := file.Stat()
239 if e != nil {
240 _ = file.Close()
241 _ = os.Remove(file.Name())
242 return nil, -1, e
243 }
244 if size != stat.Size() {
245 _ = file.Close()
246 _ = os.Remove(file.Name())
247 return nil, -1, err.NewBadRequestError(i18n.T("api.drive.invalid_file_size"))
248 }
249 return utils.NewTempFile(file), size, nil
250}
251
252func GetRequestOrigin(c *gin.Context) string {
253 host := c.GetHeader("X-Forwarded-Host")

Callers 2

writeContentMethod · 0.85
uploadMethod · 0.85

Calls 10

ToInt64Function · 0.92
CopyReaderToTempFileFunction · 0.92
NewTaskContextFunction · 0.92
TFunction · 0.92
NewTempFileFunction · 0.92
StatMethod · 0.65
CloseMethod · 0.65
NameMethod · 0.65
SizeMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected