Allow to upload files
This commit is contained in:
parent
7855e07a96
commit
8149f9f820
3 changed files with 79 additions and 46 deletions
|
@ -62,6 +62,30 @@ func getObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// createObjectHandler allows to upload a new object
|
||||||
|
func createObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
|
||||||
|
err := r.ParseMultipartForm(32 << 20)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
file, handler, err := r.FormFile("file")
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
fmt.Fprintf(w, "%v", handler.Header)
|
||||||
|
|
||||||
|
_, err = minioClient.PutObject(vars["bucketName"], handler.Filename, file, "application/octet-stream")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// deleteObjectHandler deletes an object
|
// deleteObjectHandler deletes an object
|
||||||
func deleteObjectHandler(w http.ResponseWriter, r *http.Request) {
|
func deleteObjectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
|
|
@ -44,6 +44,12 @@ var routes = Routes{
|
||||||
"/api/buckets/{bucketName}/objects/{objectName}",
|
"/api/buckets/{bucketName}/objects/{objectName}",
|
||||||
getObjectHandler,
|
getObjectHandler,
|
||||||
},
|
},
|
||||||
|
Route{
|
||||||
|
"Upload Object",
|
||||||
|
"POST",
|
||||||
|
"/api/buckets/{bucketName}/objects",
|
||||||
|
createObjectHandler,
|
||||||
|
},
|
||||||
Route{
|
Route{
|
||||||
"Delete Object",
|
"Delete Object",
|
||||||
"DELETE",
|
"DELETE",
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div class="container">
|
<div class="section">
|
||||||
<div class="section">
|
|
||||||
|
|
||||||
<table class="highlight bordered">
|
<table class="highlight bordered">
|
||||||
|
|
||||||
|
@ -22,7 +21,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{{ range $object := .Objects }}
|
{{ range $index, $object := .Objects }}
|
||||||
<tr>
|
<tr>
|
||||||
<td><i class="material-icons">{{ $object.Icon }}</i></td>
|
<td><i class="material-icons">{{ $object.Icon }}</i></td>
|
||||||
<td>{{ $object.Key }}</td>
|
<td>{{ $object.Key }}</td>
|
||||||
|
@ -31,12 +30,12 @@
|
||||||
<td>{{ $object.LastModified }}</td>
|
<td>{{ $object.LastModified }}</td>
|
||||||
<td>
|
<td>
|
||||||
<!-- Dropdown Trigger -->
|
<!-- Dropdown Trigger -->
|
||||||
<a class='dropdown-button' href='#' data-activates='actions-dropdown-{{ $object.Key }}'>
|
<a class='dropdown-button' href='#' data-activates='actions-dropdown-{{ $index }}'>
|
||||||
Actions <i class="material-icons right">arrow_drop_down</i>
|
Actions <i class="material-icons right">arrow_drop_down</i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<!-- Dropdown Structure -->
|
<!-- Dropdown Structure -->
|
||||||
<ul id='actions-dropdown-{{ $object.Key }}' class='dropdown-content'>
|
<ul id='actions-dropdown-{{ $index }}' class='dropdown-content'>
|
||||||
<li><a href="/api/buckets/{{ $.BucketName }}/objects/{{ $object.Key }}">Download</a></li>
|
<li><a href="/api/buckets/{{ $.BucketName }}/objects/{{ $object.Key }}">Download</a></li>
|
||||||
<li><a href="#" onclick="deleteObject({{ $object.Key }})">Delete</a></li>
|
<li><a href="#" onclick="deleteObject({{ $object.Key }})">Delete</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -52,7 +51,6 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<p></p>
|
<p></p>
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="fixed-action-btn">
|
<div class="fixed-action-btn">
|
||||||
|
@ -67,17 +65,22 @@
|
||||||
<br>
|
<br>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s6">
|
<div class="col s6">
|
||||||
<form action="/api/buckets" method="POST" id="create-bucket-form">
|
<form action="/api/buckets/{{ .BucketName }}/objects" method="POST" id="create-object-form" enctype="multipart/form-data">
|
||||||
<div class="input-field">
|
<div class="file-field input-field">
|
||||||
<input placeholder="My Bucket" id="name" type="text" name="name">
|
<div class="btn">
|
||||||
<label for="name">Name</label>
|
<span>File</span>
|
||||||
|
<input type="file" name="file">
|
||||||
|
</div>
|
||||||
|
<div class="file-path-wrapper">
|
||||||
|
<input class="file-path validate" type="text">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="submit" form="create-bucket-form" class="modal-action modal-close waves-effect waves-green btn-flat">Create</button>
|
<button type="submit" form="create-object-form" class="modal-action modal-close waves-effect waves-green btn-flat">Upload</button>
|
||||||
<button class="modal-action modal-close waves-effect waves-green btn-flat">Cancel</button>
|
<button class="modal-action modal-close waves-effect waves-green btn-flat">Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue