FileStorage: Add upload form (#46749)

* move upload to http

* use storage from grafanads

* rever gomod changes

* fix test

* wip

* add upload func

* update upload func

* writing to uploads

* edit response from service

* use dropzone for UI

* modify response struct in service

* better read file

* set content type for svg

* restrict file types upload

* add test and clean up errors

* pass test

* fix backend lint errors

* limit type of files on FE

* add TODO for after merge

* rebase with storage changes

* comment out unused function

* update UI to not have 2 uploads

* only call upload on select

* use utils function to find * in path

* show preview on drag over

* not allowing upload of svg

* add preview to upload tab

* no console.log

* resolve conflicts

* refactor log line

* fix failing BE test

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
Co-authored-by: Artur Wierzbicki <artur.wierzbicki@grafana.com>
This commit is contained in:
An
2022-04-27 15:12:48 -04:00
committed by GitHub
parent 4b417c8f3e
commit 900d9bf9a1
7 changed files with 361 additions and 27 deletions
+20
View File
@@ -3,12 +3,17 @@ package store
import (
"bytes"
"context"
"mime/multipart"
"os"
"path"
"path/filepath"
"testing"
"github.com/grafana/grafana-plugin-sdk-go/experimental"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb/testdatasource"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -45,3 +50,18 @@ func TestListFiles(t *testing.T) {
err = experimental.CheckGoldenFrame(path.Join("testdata", "public_testdata_js_libraries.golden.txt"), frame, true)
require.NoError(t, err)
}
func TestUpload(t *testing.T) {
features := featuremgmt.WithFeatures(featuremgmt.FlagStorageLocalUpload)
path, err := os.Getwd()
require.NoError(t, err)
cfg := &setting.Cfg{AppURL: "http://localhost:3000/", DataPath: path}
s := ProvideService(nil, features, cfg)
testForm := &multipart.Form{
Value: map[string][]string{},
File: map[string][]*multipart.FileHeader{},
}
res, err := s.Upload(context.Background(), nil, testForm)
require.NoError(t, err)
assert.Equal(t, res.path, "upload")
}