Commit 2b3f2258 authored by Lukas Böhm's avatar Lukas Böhm 🎱
Browse files

file upload working

parent a07bd9cf
node_modules
.idea
media
build
......@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/rs/cors"
"gorm.io/driver/sqlserver"
"gorm.io/gorm"
"io/ioutil"
......@@ -65,11 +66,24 @@ func getAttachment(w http.ResponseWriter, r *http.Request) {
}
func addAttachment(w http.ResponseWriter, r *http.Request) {
//allowCors(w)
if r.Method == http.MethodOptions {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
w.Header().Set("Access-Control-Max-Age", "3600")
w.WriteHeader(http.StatusNoContent)
return
}
// Set CORS headers for the main request.
w.Header().Set("Access-Control-Allow-Origin", "*")
db := getDatabase()
fmt.Fprintf(w, "Uploading File")
r.ParseMultipartForm(10 << 20) // Maximum 10 MB in RAM
file, handler, err := r.FormFile("myFile")
file, handler, err := r.FormFile("files")
if err != nil {
fmt.Println("Error Retrieving the File")
fmt.Println(err)
......@@ -121,10 +135,11 @@ func configureRoutes() {
router.HandleFunc("/share/{id}", getShare).Methods("GET")
router.HandleFunc("/share/{id}/attachments", allAttachments).Methods("GET")
router.HandleFunc("/share/{id}/attachments", addAttachment).Methods("POST")
router.HandleFunc("/share/{id}/attachments", addAttachment).Methods("POST", "OPTIONS")
router.HandleFunc("/share/{id}/attachment/{att}", getAttachment).Methods("GET")
log.Fatal(http.ListenAndServe(":6969", router))
handler := cors.Default().Handler(router)
log.Fatal(http.ListenAndServe(":6969", handler))
}
func getDatabase()(db *gorm.DB) {
......@@ -137,6 +152,7 @@ func getDatabase()(db *gorm.DB) {
}
func sendJSON(w http.ResponseWriter, res interface{}) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
......
......@@ -6,6 +6,7 @@ require (
github.com/denisenkom/go-mssqldb v0.9.0 // indirect
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0
github.com/rs/cors v1.7.0
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
gorm.io/driver/sqlserver v1.0.6
gorm.io/gorm v1.21.2
......
......@@ -11,6 +11,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E=
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
......
......@@ -5294,6 +5294,16 @@
"schema-utils": "^2.5.0"
}
},
"filepond": {
"version": "4.25.1",
"resolved": "https://registry.npmjs.org/filepond/-/filepond-4.25.1.tgz",
"integrity": "sha512-8UPPTzfpHZRUtJl3dEcGMLYOygg8taJZpYTv1WaEkvzeI+X0JX9+agMJ+5Lu1EKtdt9dGq/9Gud+EnNRBaGl1A=="
},
"filepond-plugin-file-validate-type": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/filepond-plugin-file-validate-type/-/filepond-plugin-file-validate-type-1.2.5.tgz",
"integrity": "sha512-SsdYD6N+PDnetrPrBHfl13ZC9jRv5BuGdai5cORfANhuE/N32OwU/IclCNQ4qlpIa88hzqBg9dj6IINkiW+4HA=="
},
"filesize": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/filesize/-/filesize-3.6.1.tgz",
......@@ -10950,6 +10960,11 @@
}
}
},
"vue-filepond": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/vue-filepond/-/vue-filepond-6.0.3.tgz",
"integrity": "sha512-m0wArAdpgzOOs19bWA6zzYlHAb2aK+igPoKPZGrzpgKiiELPKW7XZ2OBDXzk7rhpFLkedujVrMqwjPyZfmQTTQ=="
},
"vue-hot-reload-api": {
"version": "2.3.4",
"resolved": "https://registry.npmjs.org/vue-hot-reload-api/-/vue-hot-reload-api-2.3.4.tgz",
......
......@@ -9,7 +9,10 @@
},
"dependencies": {
"core-js": "^3.6.5",
"filepond": "^4.25.1",
"filepond-plugin-file-validate-type": "^1.2.5",
"vue": "^2.6.11",
"vue-filepond": "^6.0.3",
"vue-router": "^3.2.0"
},
"devDependencies": {
......
<template>
<div class="home">
<h1>HELLO</h1>
<div id="app">
<file-pond
name="files"
ref="pond"
label-idle="Hier hochladen..."
v-bind:allow-multiple="true"
server="http://localhost:6969/share/3a325c5b-e8b7-48f2-838c-0e2cfd73aad1/attachments"
v-bind:files="myFiles"
/>
</div>
</template>
<script>
import vueFilePond from "vue-filepond";
import "filepond/dist/filepond.min.css";
import FilePondPluginFileValidateType from "filepond-plugin-file-validate-type";
const FilePond = vueFilePond(FilePondPluginFileValidateType);
export default {
name: 'Home'
}
name: "app",
data: function () {
return { myFiles: [] };
},
components: {
FilePond,
},
};
</script>
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