Commit 0a71821f authored by Lukas Böhm's avatar Lukas Böhm 🎱
Browse files

remove old upload func

parent bb3f27c8
Pipeline #59176 failed with stages
in 9 seconds
......@@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/rs/cors"
"gorm.io/driver/sqlserver"
......@@ -92,60 +91,8 @@ func CloseShare(w http.ResponseWriter, r *http.Request) {
SendJSON(w, share)
}
func UploadAttachment(w http.ResponseWriter, r *http.Request) {
fmt.Println("UploadAttachment")
db := GetDatabase()
vars := mux.Vars(r)
// Prase multipart (file) data
err := r.ParseMultipartForm(CHUNK_SIZE)
if err != nil {
fmt.Println(err)
}
// Parse file
file, handler, err := r.FormFile("files")
if err != nil {
fmt.Println("Error Retrieving the File")
fmt.Println(err)
return
}
defer file.Close()
// get vars
shareId, err := uuid.Parse(vars["id"])
if err != nil {
fmt.Println(err)
}
attId, err := uuid.Parse(vars["att"])
if err != nil {
fmt.Println(err)
}
fmt.Println(attId)
// create attachment in db
db.Create(&Attachment{
Filename: handler.Filename,
Filesize: handler.Size,
ShareID: shareId,
})
// save file
fileBytes, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println(err)
}
err = ioutil.WriteFile(filepath.Join("media", vars["id"], handler.Filename), fileBytes, 0777)
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Uploaded File")
return // just return, status code is enough information
}
func UploadTest(w http.ResponseWriter, r *http.Request) {
func UploadAttachment(w http.ResponseWriter, r *http.Request) {
log.Println("UploadTest")
vars := mux.Vars(r)
......@@ -184,7 +131,7 @@ func ConfigureRoutes() {
router.HandleFunc("/shares", OpenShare).Methods("POST")
router.HandleFunc("/share/{id}", CloseShare).Methods("POST")
router.HandleFunc("/share/{id}/attachments", UploadTest).Methods("POST") // todo change to addattachment
router.HandleFunc("/share/{id}/attachments", UploadAttachment).Methods("POST")
log.Fatal(http.ListenAndServe(":6969", handler))
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment