Beispiel #1
0
func (h HTTPSHandler) putBlob(w http.ResponseWriter, r *http.Request) {
	_, blobID := path.Split(r.URL.Path)
	blobManager := blobstore.NewBlobManager(h.fs, h.dirProvider.MicroStore())

	payload, err := ioutil.ReadAll(r.Body)
	if err != nil {
		w.WriteHeader(500)
		if _, wErr := w.Write([]byte(err.Error())); wErr != nil {
			h.logger.Error("https_handler", "Failed to write response body: %s", wErr.Error())
		}

		return
	}

	err = blobManager.Write(blobID, payload)
	if err != nil {
		w.WriteHeader(500)
		if _, wErr := w.Write([]byte(err.Error())); wErr != nil {
			h.logger.Error("https_handler", "Failed to write response body: %s", wErr.Error())
		}
		return
	}

	w.WriteHeader(201)
}
Beispiel #2
0
func (h HTTPSHandler) getBlob(w http.ResponseWriter, r *http.Request) {
	_, blobID := path.Split(r.URL.Path)
	blobManager := blobstore.NewBlobManager(h.fs, h.dirProvider.MicroStore())

	blobBytes, err := blobManager.Fetch(blobID)

	if err != nil {
		w.WriteHeader(404)
	} else {
		if _, wErr := w.Write(blobBytes); wErr != nil {
			h.logger.Error("https_handler", "Failed to write response body: %s", wErr.Error())
		}
	}
}
func (h HTTPSHandler) getBlob(w http.ResponseWriter, r *http.Request) {
	_, blobID := path.Split(r.URL.Path)
	blobManager := blobstore.NewBlobManager(h.fs, h.dirProvider.MicroStore())

	file, err, statusCode := blobManager.Fetch(blobID)

	if err != nil {
		h.logger.Error("https_handler", "Failed to fetch blob: %s", err.Error())

		w.WriteHeader(statusCode)

	} else {
		defer func() {
			_ = file.Close()
		}()
		reader := bufio.NewReader(file)
		if _, wErr := io.Copy(w, reader); wErr != nil {
			h.logger.Error("https_handler", "Failed to write response body: %s", wErr.Error())
		}
	}
}