diff --git a/modules/storage/obs.go b/modules/storage/obs.go index d174b8fba..4e364fe9c 100755 --- a/modules/storage/obs.go +++ b/modules/storage/obs.go @@ -5,7 +5,7 @@ package storage import ( - "io" + "github.com/unknwon/com" "path" "strconv" "strings" @@ -102,57 +102,27 @@ func CompleteObsMultiPartUpload(uuid string, uploadID string) error { return nil } -func ObsUploadPart(uuid string, uploadId string, partNumber int, partSize int64, body io.Reader) (string, error) { - input := &obs.UploadPartInput{} - input.PartNumber = partNumber - input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, uuid)), "/") - input.UploadId = uploadId - input.Bucket = setting.Bucket - input.PartSize = partSize - input.Body = body - output, err := ObsCli.UploadPart(input) - if err != nil { - log.Error("UploadPart failed:", err.Error()) - return "", err - } - - return output.ETag, nil -} - func ObsGenMultiPartSignedUrl(uuid string, uploadId string, partNumber int, partSize int64) (string, error) { - /* + input := &obs.CreateSignedUrlInput{} input.Bucket = setting.Bucket - input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid)), "/") - input.Expires = int(PresignedUploadPartUrlExpireTime) - input.Method = obs.HTTP_PUT + input.Key = strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, uuid)), "/") + input.Expires = 60 * 60 + input.Method = obs.HttpMethodPut input.QueryParams = map[string]string{ - "Bucket": input.Bucket, - "Key": input.Key, - "PartNumber": com.ToStr(partNumber,10), - "UploadId": uploadId, - "PartSize": com.ToStr(partSize,10), + "partNumber": com.ToStr(partNumber,10), + "uploadId": uploadId, + //"partSize": com.ToStr(partSize,10), } - input.Headers = map[string]string{ - - } - - */ - - Key := strings.TrimPrefix(path.Join(setting.BasePath, path.Join(uuid[0:1], uuid[1:2], uuid, uuid)), "/") - req, err := ObsCli.CreateUploadPartSignedUrl(setting.Bucket, Key, uploadId, partNumber, partSize) + output, err := ObsCli.CreateSignedUrl(input) if err != nil { log.Error("CreateSignedUrl failed:", err.Error()) return "", err } - log.Info(req.URL.String()) - log.Info("", req.Header) - - return req.URL.String(), nil - + return output.SignedUrl, nil } func ObsGetPreSignedUrl(uuid, fileName string) (string, error) { diff --git a/routers/repo/attachment.go b/routers/repo/attachment.go index 6874a1eda..cab123d30 100755 --- a/routers/repo/attachment.go +++ b/routers/repo/attachment.go @@ -422,14 +422,13 @@ func GetSuccessChunks(ctx *context.Context) { return } } else { - isExist, err = storage.ObsHasObject(models.AttachmentRelativePath(fileChunk.UUID)) + isExist, err = storage.ObsHasObject(setting.BasePath + models.AttachmentRelativePath(fileChunk.UUID) + "/" + fileChunk.UUID) if err != nil { ctx.ServerError("ObsHasObject failed", err) return } } - if isExist { if fileChunk.IsUploaded == models.FileNotUploaded { log.Info("the file has been uploaded but not recorded") @@ -633,38 +632,6 @@ func GetObsKey(ctx *context.Context) { }) } -func UploadPart(ctx *context.Context) { - tmp, err := ctx.Req.Body().String() - log.Info(tmp) - - err = ctx.Req.ParseMultipartForm(100*1024*1024) - if err != nil { - ctx.Error(http.StatusBadRequest, fmt.Sprintf("ParseMultipartForm failed: %v", err)) - return - } - - file, fileHeader, err := ctx.Req.FormFile("file") - log.Info(ctx.Req.Form.Get("file")) - if err != nil { - ctx.Error(http.StatusBadRequest, fmt.Sprintf("FormFile failed: %v", err)) - return - } - - - - log.Info(fileHeader.Filename) - - etag, err := storage.ObsUploadPart("", "", 1, 1, file) - if err != nil { - ctx.Error(500, fmt.Sprintf("ObsUploadPart failed: %v", err)) - return - } - - ctx.JSON(200, map[string]string{ - "etag": etag, - }) -} - func CompleteMultipart(ctx *context.Context) { uuid := ctx.Query("uuid") uploadID := ctx.Query("uploadID") @@ -724,15 +691,17 @@ func CompleteMultipart(ctx *context.Context) { } if attachment.DatasetID != 0 { - if strings.HasSuffix(attachment.Name, ".zip") { - err = worker.SendDecompressTask(contexExt.Background(), uuid) - if err != nil { - log.Error("SendDecompressTask(%s) failed:%s", uuid, err.Error()) - } else { - attachment.DecompressState = models.DecompressStateIng - err = models.UpdateAttachment(attachment) + if typeCloudBrain == models.TypeCloudBrainOne { + if strings.HasSuffix(attachment.Name, ".zip") { + err = worker.SendDecompressTask(contexExt.Background(), uuid) if err != nil { - log.Error("UpdateAttachment state(%s) failed:%s", uuid, err.Error()) + log.Error("SendDecompressTask(%s) failed:%s", uuid, err.Error()) + } else { + attachment.DecompressState = models.DecompressStateIng + err = models.UpdateAttachment(attachment) + if err != nil { + log.Error("UpdateAttachment state(%s) failed:%s", uuid, err.Error()) + } } } } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 312707314..adc8938a9 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -529,7 +529,6 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/get_multipart_url", repo.GetMultipartUploadUrl) m.Post("/complete_multipart", repo.CompleteMultipart) m.Post("/update_chunk", repo.UpdateMultipart) - m.Post("/upload_part", repo.UploadPart) m.Get("/get_obs_key", repo.GetObsKey) }, reqSignIn) diff --git a/web_src/js/components/MinioUploader.vue b/web_src/js/components/MinioUploader.vue index c453daf16..3ece6994e 100755 --- a/web_src/js/components/MinioUploader.vue +++ b/web_src/js/components/MinioUploader.vue @@ -21,6 +21,7 @@ import qs from 'qs'; import createDropzone from '../features/dropzone.js'; const {_AppSubUrl, _StaticUrlPrefix, csrf} = window.config; +const CloudBrainType = 0; export default { data() { @@ -245,8 +246,8 @@ export default { file_name: file.name, size: file.size, dataset_id: file.datasetId, - _csrf: csrf, - type:0 + type: CloudBrainType, + _csrf: csrf }) ); } @@ -284,6 +285,7 @@ export default { md5: file.uniqueIdentifier, size: file.size, fileType: file.type, + type: CloudBrainType, _csrf: csrf } }); @@ -324,6 +326,7 @@ export default { uploadID: file.uploadID, size: partSize, chunkNumber: currentChunk + 1, + type: CloudBrainType, _csrf: csrf } }); @@ -382,6 +385,7 @@ export default { file_name: file.name, size: file.size, dataset_id: file.datasetId, + type: CloudBrainType, _csrf: csrf }) ); diff --git a/web_src/js/components/ObsUploader.vue b/web_src/js/components/ObsUploader.vue index e61981c7e..16b53d343 100755 --- a/web_src/js/components/ObsUploader.vue +++ b/web_src/js/components/ObsUploader.vue @@ -4,22 +4,24 @@ id="dataset" class="dropzone" /> -

{{ file_status_text }} {{ status }}

- +