Как отправить файл на S3 с помощью vuejs с заранее заданным URL? - PullRequest
0 голосов
/ 22 октября 2018

Я хочу загрузить файл в Minio, используя vuejs.

Итак, я добавил следующий код в свой проект vue

<template>
<div class="app-container">


<h1>Minio Code</h1>
<input type="file" id="selector" multiple>
<button v-on:click="upload()">Upload</button>

<div id="status">No uploads</div>

</div>

</template>

<script>
import $ from 'jquery'
    export default
    {
        name: 'presigned',
[.......]
        methods:
        {
              upload()
            {
                 [$('#selector')[0].files].forEach(fileObj =>

                {
                    var file = fileObj[0]
                    // Retrieve a URL from our server.

                    this.retrieveNewURL(file, url =>
                    {
                        // Upload the file to the server.

                        this.uploadFile(file, url)
                    })
                })
            },

            // Request to our Node.js server for an upload URL.
            retrieveNewURL(file, cb)
            {
                $.get(this.$baseUrl + `upload/presigned?filename=${file.name}`, (url) =>
                {
                    cb(url)
                })
            },

            // Use XMLHttpRequest to upload the file to S3.
            uploadFile(file, url)
            {
                console.log(url)
                var xhr = new XMLHttpRequest()
                xhr.open('PUT', url, true)
                xhr.send(file)
                xhr.onload = () =>
                {
                    if (xhr.status == 200)
                    {
                        $('#status').text(`Uploaded ${file.name}.`)
                    }
                }
            }

        }
    }
</script>

Это модифицированный код из учебника со страницы мини-страниц здесь .Но когда я нажимаю кнопку загрузки, я получаю только ошибку 404

PUT http://localhost:9528/[object%20Object] 404 (Not Found)

Что еще мне нужно добавить, чтобы напрямую загрузить файл в Minio.

...