首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Axios缺省值在laravel蒸气签署-存储-url

使用Axios缺省值在laravel蒸气签署-存储-url
EN

Stack Overflow用户
提问于 2019-10-21 20:01:51
回答 1查看 1.7K关注 0票数 0

使用Tymon令牌作为auth。拉勒维尔工作得很好。

当使用用于Laravel蒸气的上载到S3代码时,我无法获得已签名的存储-url来使用我的axios默认值:

axios.defaults.headers.common["Authorization"] = 'Bearer ' + token;

存储方法,如文档中所示:

代码语言:javascript
复制
Vapor.store(this.$refs.file.files[0], {
    progress: progress => {
        this.uploadProgress = Math.round(progress * 100);
    }
}).then(response => {
...

它在npm包的index.js中将此称为:

代码语言:javascript
复制
async store(file, options = null) {
        // want this to use my default header.
        const response = await axios.post('/vapor/signed-storage-url', {
            'bucket': options.bucket || '',
            'content_type': options.contentType || file.type,
            'expires': options.expires || ''
        });

也许是因为npm模块没有在正确的范围内。

我已经重写了蒸气核心签名存储url控制器来使用令牌,并且可以让它与邮递员一起工作。调用Vapor.store没有将令牌添加到axios调用中,而且我没有看到传递标头的方法。

编辑:您可以不用注册Vapor就可以使用这些包。

代码语言:javascript
复制
composer require laravel/vapor-core

代码语言:javascript
复制
npm install --save-dev laravel-vapor
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-25 05:58:43

解决了问题,因此为了完成这项工作,我将异步存储方法复制到vue组件方法中,并从那里调用它。获取默认标题,但是..。

这在S3中创建了一个axios头问题,通过这样做解决了这个问题:

代码语言:javascript
复制
async store(file, options = null) {
            const response = await axios.post('/vapor/signed-storage-url', {
                'bucket': options.bucket || '',
                'content_type': options.contentType || file.type,
                'expires': options.expires || ''
            });

            if (typeof options.progress === 'undefined') {
                options.progress = () => {};
            }
// This is the fix for the headers. Instance just for the S3 PUT
            var instance = axios.create();
            instance.defaults.headers.common = {};
            const s3Response = await instance.put(response.data.url, file, {
                headers: response.data.headers,
                onUploadProgress: (progressEvent) => {
                    options.progress(progressEvent.loaded / progressEvent.total);
                }
            });

            response.data.extension = file.name.split('.').pop()

            return response.data;
        },

多亏了https://github.com/axios/axios/issues/382#issuecomment-254712154

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58493339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档