update for the javascript
This commit is contained in:
52
main.go
52
main.go
@@ -256,19 +256,45 @@ func uploadFileForServer(sqldb *sql.DB, lang string) http.Handler{
|
||||
}
|
||||
func upload() http.Handler {
|
||||
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request){
|
||||
file, header, _ := req.FormFile("myFile")
|
||||
req.ParseMultipartForm(10000000<<20)
|
||||
defer file.Close()
|
||||
filename := header.Filename
|
||||
tempFile, _ :=os.CreateTemp("Data",header.Filename)
|
||||
defer tempFile.Close()
|
||||
fileBytes,_:=io.ReadAll(file)
|
||||
tempFile.Write(fileBytes)
|
||||
fn,_:=os.OpenFile("Data/"+filename, os.O_WRONLY|os.O_CREATE, 0666)
|
||||
defer fn.Close()
|
||||
fn.Write(fileBytes)
|
||||
slog.Info(fmt.Sprint(getDataFromFile("Data/"+filename)))
|
||||
})}
|
||||
file, header, err := req.FormFile("myFile")
|
||||
if err != nil {
|
||||
http.Error(res, "Failed to read file", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
req.ParseMultipartForm(10000000<<20)
|
||||
filename := header.Filename
|
||||
tempFile, err := os.CreateTemp("Data", header.Filename)
|
||||
if err != nil {
|
||||
http.Error(res, "Failed to create temp file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tempFile.Close()
|
||||
fileBytes, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
http.Error(res, "Failed to read file bytes", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_, err = tempFile.Write(fileBytes)
|
||||
if err != nil {
|
||||
http.Error(res, "Failed to write to temp file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
fn, err := os.OpenFile("Data/"+filename, os.O_WRONLY|os.O_CREATE, 0666)
|
||||
if err != nil {
|
||||
http.Error(res, "Failed to open file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer fn.Close()
|
||||
_, err = fn.Write(fileBytes)
|
||||
if err != nil {
|
||||
http.Error(res, "Failed to write to file", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
slog.Info(fmt.Sprint(getDataFromFile("Data/" + filename)))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// index creates an HTTP handler that serves the main page with data from the database.
|
||||
// sqldb: The database connection object.
|
||||
|
Reference in New Issue
Block a user