Example #1
0
// @Title Upload
// @Description Upload a new data set to server by file path
// @Param	filePath	form 	string	true		"The data set file path, must as same server"
// @Param	dropHeader	form 	bool	true		"The data set if has header"
// @Success 200 {string} the data set id
// @Failure 403 {string} error description
// @router /upload/path [post]
func (o *DataSetController) UploadByPath() {
	filePath := o.GetString("filePath")

	dropHeader, err := o.GetBool("dropHeader")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	filename := utility.AcquireFilename()
	_, err = utility.CopyFile(filePath, "../store/"+filename)
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	lineNumber, err := utility.GetFileLineNumber("../store/" + filename)
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	id, err := models.AddDataSet(filename, lineNumber, dropHeader)
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	o.Ctx.WriteString(strconv.Itoa(int(id)))
}
Example #2
0
// @Title Upload
// @Description Upload result set
// @Param	file		form 	file	true		"Result set data"
// @Param	jobSliceId	form 	int64	true		"The job slice id"
// @Success 200 body is empty
// @Failure 403 {string} error description
// @router /upload [post]
func (o *ResultSetController) Upload() {
	f, _, err := o.GetFile("file")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}
	defer f.Close()

	//	fileSize, err := o.GetInt64("fileSize")
	//	if err != nil {
	//		log.Println(err)
	//		FinishRequest(o.Ctx, 403, err.Error())
	//		return
	//	}

	jobSliceId, err := o.GetInt64("jobSliceId")
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	filename := utility.AcquireFilename()
	_, err = utility.CopyFile2(f, "../store/"+filename)
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}

	err = models.CompletedJobSlice(jobSliceId, filename)
	if err != nil {
		log.Println(err)
		FinishRequest(o.Ctx, 403, err.Error())
		return
	}
}